Java Quiz 9 : Control Statements II By Tejas Chaudhari - September 1, 2021 FacebookTwitterPinterestWhatsApp Welcome to your Java Quiz 9 : Control Statements II 1. What will be the output of the following Java program? class selection_statements { public static void main(String args[]) { int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) System.out.print(var2); else System.out.print(++var2); } } a) 1b) 2c) 3d) 4 2. What will be the output of the following Java program? class comma_operator { public static void main(String args[]) { int sum = 0; for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) sum += i; System.out.println(sum); } } a) 5b) 6c) 14d) compilation error 3. What will be the output of the following Java 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 + " "); } } } a) 1 3 5 7b) 2 4 6 8c) 1 3 5 7 9d) 1 2 3 4 5 6 7 8 9 4. What will be the output of the following Java program? class Output { public static void main(String args[]) { final int a=10,b=20; while(a<b) { System.out.println("Hello"); } System.out.println("World"); } } a) Hellob) run time errorc) Hello worldd) compile time error 5. What will be the output of the following Java program? class Output { public static void main(String args[]) { int a = 5; int b = 10; first: { second: { third: { if (a == b >> 1) break second; } System.out.println(a); } System.out.println(b); } } } a) 5 10b) 10 5c) 5d) 10 6. What would be the output of the following code snippet if variable a=10? if(a<=0) { if(a==0) { System.out.println("1 "); } else { System.out.println("2 "); } } System.out.println("3 "); a) 1 2b) 2 3c) 1 3d) 3 7. The while loop repeats a set of code while the condition is not met?a) Trueb) False 8. What is true about a break?a) Break stops the execution of entire programb) Break halts the execution and forces the control out of the loopc) Break forces the control out of the loop and starts the execution of next iterationd) Break halts the execution of the loop for certain time frame 9. What is true about do statement?a) do statement executes the code of a loop at least onceb) do statement does not get execute if condition is not matched in the first iterationc) do statement checks the condition at the beginning of the loopd) do statement executes the code more than once alwaysf 10. Which of the following is used with the switch statement?a) Continueb) Exitc) breakd) do 11. What is the valid data type for variable “a” to print “Hello World”? switch(a) { System.out.println("Hello World"); } a) int and floatb) byte and shortc) char and longd) byte and char 12. Which of the following is not a decision making statement?a) ifb) if-elsec) switchd) do-while 13. Which of the following is not a valid jump statement?a) breakb) gotoc) continued) return 14. From where break statement causes an exit?a) Only from innermost loopb) Terminates a programc) Only from innermost switchd) From innermost loops or switches 15. Which of the following is not a valid flow control statement?a) exit()b) breakc) continued) return Time is Up!