Home » JAVA Programming » Decision Making » Question
  1. 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 + " ");
    }
    }
    }
    }
    1. 5 6 7 9
    2. 1 2 3 4 5
    3. 2 3 4 5
    4. 6 7 8 9
    5. 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



Your comments will be displayed only after manual approval.