Flow Control

1

What will be the output of the program?

int I = 0;
label:
    if (I < 2) {
    System.out.print("I is " + I);
    I++;
    continue label;
}
A. I is 0
B. I is 0 I is 1
C. Compilation fails.
D. None of the above

2

What will be the output of the program?

int i = 0, j = 5; 
tp: for (;;) 
    {
        i++;  
        for (;;) 
        {
            if(i > --j) 
            {
                break tp; 
            } 
        } 
        System.out.println("i =" + i + ", j = " + j);
A. i = 1, j = 0
B. i = 1, j = 4
C. i = 3, j = 4
D. Compilation fails.

3

What will be the output of the program?

public class Switch2 
{
    final static SHORT x = 2;
    public static int y = 0;
    public static void main(String [] args) 
    {
        for (int z=0; z < 4; z++) 
        {
            switch (z) 
            {
                case x: System.out.print("0 ");
                default: System.out.print("def ");
                case x-1: System.out.print("1 ");  
                            break;
                case x-2: System.out.print("2 ");
            }
        }
    }
}
A. 0 def 1
B. 2 1 0 def 1
C. 2 1 0 def def
D. 2 1 0 def 1 def 1

4

What will be the output of the program?

boolean bool = true; 
if(bool = false) /* Line 2 */
{
    System.out.println("a"); 
} 
else if(bool) /* Line 6 */
{
    System.out.println("b"); 
} 
else if(!bool) /* Line 10 */
{
    System.out.println("c"); /* Line 12 */
} 
else 
{
    System.out.println("d"); 
}
A. a
B. b
C. c
D. d

5

What will be the output of the program?

public class Test 
{  
    public static void main(String args[]) 
    { 
        int i = 1, j = 0; 
        switch(i) 
        { 
            case 2: j += 6; 
            case 4: j += 1; 
            default: j += 2; 
            case 0: j += 4; 
        } 
        System.out.println("j = " + j); 
    } 
}
A. j = 0
B. j = 2
C. j = 4
D. j = 6