-
What is the output of this program?
public class jump_statment_Example
{
public static void main(String args[])
{
int p = 4;
int q = 5;
for ( ; q < 10; ++q)
{
if (q % p == 0)
{
continue;
}
else if (q == 10)
{
break;
}
else
{
System.out.print(q + " ");
}
}
}
}
-
- 5 6 7 9
- 1 2 3 4 5
- 2 3 4 5
- 6 7 8 9
- None of these
Correct Option: A
Whenever q is divisible by x remainder body of loop is skipped by continue statement, therefore if condition q == 10 is never true as when y is 10, remainder body of loop is skipped by continue statements of first if. Control comes to print statement only in cases when q is odd.
output: 5 6 7 9