Java Quiz 9 : Control Statements II

    Welcome to your Java Quiz 9 : Control Statements II

    1. What will be the output of the following Java program?
    1.  class selection_statements 
    2.  {
    3.  public static void main(String args[])
    4.  {
    5.  int var1 = 5; 
    6.  int var2 = 6;
    7.  if ((var2 = 1) == var1)
    8.  System.out.print(var2);
    9.  else 
    10.  System.out.print(++var2);
    11.  } 
    12.  }
    2. What will be the output of the following Java program?
    1.  class comma_operator 
    2.  {
    3.  public static void main(String args[]) 
    4.  { 
    5.  int sum = 0;
    6.  for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
    7.  sum += i;
    8.  System.out.println(sum);
    9.  } 
    10.  }
    3. What will be the output of the following Java program?
    1.  class jump_statments 
    2.  {
    3.  public static void main(String args[]) 
    4.  { 
    5.  int x = 2;
    6.  int y = 0;
    7.  for ( ; y < 10; ++y) 
    8.  {
    9.  if (y % x == 0) 
    10.  continue; 
    11.  else if (y == 8)
    12.  break;
    13.  else
    14.  System.out.print(y + " ");
    15.  }
    16.  } 
    17.  }
    4. What will be the output of the following Java program?
    1. class Output 
    2. {
    3.  public static void main(String args[]) 
    4.  { 
    5.  final int a=10,b=20;
    6.  while(a<b)
    7.  {
    8.  
    9.  System.out.println("Hello");
    10.  }
    11.  System.out.println("World");
    12.  
    13.  } 
    14. }
    5. What will be the output of the following Java program?
    1.  class Output 
    2.  {
    3.  public static void main(String args[]) 
    4.  { 
    5.  int a = 5;
    6.  int b = 10;
    7.  first: 
    8.  {
    9.  second: 
    10.  {
    11.  third: 
    12.  { 
    13.  if (a == b >> 1)
    14.  break second;
    15.  }
    16.  System.out.println(a);
    17.  }
    18.  System.out.println(b);
    19.  }
    20.  } 
    21.  }
    6. What would be the output of the following code snippet if variable a=10?
    1. if(a<=0)
    2. {
    3.  if(a==0)
    4.  {
    5.  System.out.println("1 ");
    6.  }
    7.  else 
    8.  { 
    9.  System.out.println("2 ");
    10.  }
    11. }
    12. System.out.println("3 ");
    7. The while loop repeats a set of code while the condition is not met?
    8. What is true about a break?
    9. What is true about do statement?
    10. Which of the following is used with the switch statement?
    11. What is the valid data type for variable “a” to print “Hello World”?
    1. switch(a)
    2. {
    3.  System.out.println("Hello World");
    4. }
    12. Which of the following is not a decision making statement?
    13. Which of the following is not a valid jump statement?
    14. From where break statement causes an exit?
    15. Which of the following is not a valid flow control statement?