Menu
Topics Index
...
`

Highlight test


If you need explanation Read this topic

If you need Answer Take test on this topic

Highlight test
What will be the output of the following program?
public class Highlight {
    public static void main(String[] args) {
        int[] numbers = {10, 20, 30, 40, 50, 60, 70, 80, 90};
        for (int x : numbers) {
            if (x == 30 || x == 60 || x == 90 || x == 120) {
                continue;
            }
            System.out.print(x + " ");
            continue;
        }
    }
}

A. 10 20 30 40 50 60 70 80 90 120
B. 10 20 30 40 50 60 70 80 90
C. 10 20 40 50 70 80
D. Compilation Error
E. Runtime Error
Topic: For-each Loop In Core Java Programming

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.

The answer is C. Whenever the if condition is satisfied, it continues to the next iteration. Thus it skips 30,60 and 90

Posted by Kaushik Yasaswy    2013-05-08 12:37:35


the answer is c : in for loop x takes values from the array and whenever if condition satisfies it executes continue statement where x takes the next value of array  without printing the values and if condition does not follow it prints the values... so output is 10 20 40 50 70 80....

Posted by Pramod Jain    2013-05-08 13:06:33


Congratulations Kaushik Yasaswy. You are today's daily dose winner. Please send us your mobile details and we will recharge your mobile tomorrow after considering the new likes.

Posted by Merit Campus    2013-05-08 15:56:23


Thanks!! Got the rc :D

Posted by Kaushik Yasaswy    2013-05-09 13:27:20


© meritcampus 2019

All Rights Reserved.

Open In App