Decision Making


  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. View Hint View Answer Discuss in Forum

    NA

    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


  1. What is the output of this program?

    public class selection_statement_Example
    {
    public static void main(String args[])
    {
    int num1 = 10;
    int num2 = 20;
    if ((num2 = 5) == num1)
    {
    System.out.print(num2);
    }
    else
    {
    System.out.print(++num2);
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    num2 is initialised to 5. The conditional statement returns false and the else part gets executed.
    output: 6



  1. Which of these statement is incorrect?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    No two case constants in the same switch can have identical values.


  1. Which of these jump statements can skip processing remainder of code in its body for a particular iteration?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Ans: continue



  1. Which of these are selection statements in Java?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Continue and break are jump statements, and for is an looping statement.