Programming  Java  Statements

1. Which of these selection statements test only for equality?

if switch if & switch None of the mentioned

Share this QA

2. Which of these are selection statements in Java?

if() for() continue break

Share this QA

3. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

do-while while for None of the mentioned

Share this QA

4. Which of these jump statements can skip processing remainder of code in its body for a particular iteration?

break return exit continue

Share this QA

5. Which of these statement is correct?

switch statement is more efficient than a set of nested ifs. two case constants in the same switch can have identical values. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression. it is possible to create a nested switch statements.

Share this QA

6. What is the output of this program?
class selection_statements {
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}

1 2 3 4

Share this QA

7. What is the output of this program?
class comma_operator {
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}

5 6 14 compilation error

Share this QA

8. What is the output of this program?
class jump_statments {
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y) {
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}

1 3 5 7 2 4 6 8 1 3 5 7 9 1 2 3 4 5 6 7 8 9

Share this QA

9. What is the output of this program?
class Output {
public static void main(String args[])
{
int x, y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}

1 2 Runtime error owing to division by zero in if condition. Unpredictable behavior of program.

Share this QA

10. What is the output of this program?
class Output {
public static void main(String args[])
{
int a = 5;
int b = 10;
first: {
second: {
third: {
if (a == b >> 1)
break second;
}
System.out.println(a.;
}
System.out.println(b.;
}
}
}

5 10 10 5 5 10

Share this QA

 

*Click on the QNo to display a Question.

Total Ans