Menu
Topics Index
...
`

Sum is2537


If you need explanation Read this topic

If you need Answer Take test on this topic

Sum is2537
What will be the output of the following program?
public class Mock {
    public static void main(String args[]) {
        int z = 3;
        for (int i = 0; i < 2; i++) {
            switch (z) {
                case 3 :
                    System.out.print((z = z + 1) + " ");
                case 5 :
                    System.out.print((z = z + 2) + " ");
                    break;
                default :
                    System.out.print((z = z + 8) + " ");
                case 6 :
                    System.out.print((z = z + 4) + " ");
            }
        }
    }
}

A. 12 16
B. 4 6 7
C. 4 6 10
D. 4 7 15 19
E. Compilation Error or Runtime Error
Topic: for Loop In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans:C  when i=0 enter into switch case:3 prints  4 and case:5 print 6 and then break. then when i=1 enter into case: 6 prints 10

Posted by Indrasena Reddy    2014-01-28 08:11:00


Ans is : C, In 1st iteration case 3 and case 5 are executed. and in 2nd iteration case 6 is executed.

Posted by Malli Karjun    2014-01-28 08:14:39


Congratulations Indrasena Reddy. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-29 04:49:28


© meritcampus 2019

All Rights Reserved.

Open In App