Programming  Java  Statements

Answer each question, once completed click submit.

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

if switch if & switch None of the mentioned

Workspace

Discuss

2. Which of these are selection statements in Java?

if() for() continue break

Workspace

Discuss

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

Workspace

Discuss

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

break return exit continue

Workspace

Discuss

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.

Workspace

Discuss

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

Workspace

Discuss

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

Workspace

Discuss

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

Workspace

Discuss

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.

Workspace

Discuss

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

Workspace

Discuss

11. Which of the following is TRUE about the switch statement in Java?

A default send execution immediately to the end of the switch statement. A break send execution immediately to the end of the switch statement. A case send execution immediately to the end of the switch statement. The statements in a switch continue to execute as long as the condition at the top of the switch remains true.

Workspace

Discuss

12. Which of the following is a loop construct that will always be executed once?

switch for while do...while

Workspace

Discuss

13. Which one is not a valid jump statement?

return goto continue break

Workspace

Discuss

14. Which of the following is not a valid flow control statement?

break; continue outer; return; exit();

Workspace

Discuss

15. The break statement causes an exit

only from the innermost loop. only from the innermost switch. from innermost loops or switches. terminates a program.

Workspace

Discuss
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15