Easy Tutorial
For Competitive Exams

What is the output of this program?
class jump_statments {
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y) {
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}

1 3 5 7
2 4 6 8
1 3 5 7 9
1 2 3 4 5 6 7 8 9
Explanation:
Whenever y is divisible by x remainder body of loop is skipped by continue statement,
therefore if condition y == 8 is never true as when y is 8, remainder body of loop is skipped by continue statements of first if.
Control comes to print statement only in cases when y is odd.
output:
$ javac jump_statments.java
$ java jump_statments
1 3 5 7 9
Share with Friends
Privacy Copyright Contact Us