Java Programming MCQ - Control Flow Statements
11. 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);
}
}
View Answer
12. 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);
}
}
View Answer
13. What will be the output of the program?
int i = l, j = -1;
switch (i)
{
case 0, 1: j = 1; /* Line 4 */
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);
View Answer
14. In the following code snippet, which lines of code contain error?
int j=0;
while (j < 10)
{
j++;
if (j==5) continue loop;
system.out.ptintln("j is " +j);
}
View Answer
15. What is the output of this program?
int i = 1, j = 10;
do
{ if(i > j)
{
break;
}
j--;
} while (++i < 5);
System.out.println("i = " + i + " and j = " + j);
View Answer
Also check :