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);
	}
}

A. 1
B. 2
C. 3
D. 4

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);
	}
}

A. 5
B. 6
C. 14
D. compilation error

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);

A. j = -1
B. j = 0
C. j = 1
D. Compilation fails.

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);
}

A. Line 2
B. Line 3
C. Line 4
D. Line 5

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);

A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6

View Answer






Also check :

Discussion


* You must be logged in to add comment.