if statement in Java?if (condition) { }if (condition) : { }if { condition }if condition { }int x = 5; if (x > 3) System.out.println("Hello"); else System.out.println("World");else-if statement in Java?else if(condition) {}elseif (condition) {}else if: condition {}if else (condition) {}switch statement do in Java?switch statement?int x = 3; switch (x) { case 1: System.out.println("One"); break; case 3: System.out.println("Three"); break; default: System.out.println("Other"); }break statement in a switch block?case.case.if (x == 5) {}switch (x) { case 1: break; default: break; }switch (x) { case "apple": break; }if (x > 10) {}default keyword work in a switch statement?switch statement.return in an if statement?else block.int result = (x > 5) ? 10 : 20; when x = 3?condition ? value_if_true : value_if_false;condition ? value_if_true : ;condition : value_if_true;condition = value_if_true : value_if_false;int x = (y == 5) ? "True" : "False";int x = (y > 5) ? y;int x = (y == 5) ? 10 : 20;int x = (y < 5) ? 10 else 20;int x = 5; System.out.println((x == 5) ? "Correct" : "Incorrect");if-else statement.for loops.? in a ternary operator is false?int result = condition ? "Yes" : "No";int result = condition ? value;int result = condition ? value : value;int result = condition : value : value;if-else statement: if (x > 10) { return 100; } else { return 200; }?return (x > 10) ? 100 : 200;return (x > 10) ? 200 : 100;return (x > 10) ? return 100 : return 200;return x > 10;for loopwhile loopdo-while loopforeach loopfor loop in Java?for (initialization; condition; increment) {}for (initialization; condition) {}for (condition; increment) {}for (initialization) {}for (int i = 0; i < 3; i++) { System.out.print(i); }while loop in Java?while (condition) {}while (condition) { statement;}while statement;while (condition) statementint x = 0; while (x < 5) { System.out.print(x + " "); x++; }for loopwhile loopdo-while loopforeach loopcontinueexitbreakstopfor loop?do-while loop.for (int i = 0; i < 5; i++) { if (i == 2) break; System.out.print(i); }do-while loop?if statement.| Qno | Answer |
|---|---|
| 1 | a) if (condition) { } |
| 2 | a) Hello |
| 3 | a) else if(condition) {} |
| 4 | a) It selects one of many code blocks to execute based on a condition. |
| 5 | c) Integers, Strings, and characters |
| 6 | b) Three |
| 7 | c) It terminates the entire switch statement. |
| 8 | c) switch (x) { case "apple": break; } |
| 9 | b) It handles the cases that are not defined. |
| 10 | b) It exits the method and returns control to the calling method. |
| 11 | b) 20 |
| 12 | a) condition ? value_if_true : value_if_false; |
| 13 | b) It allows you to assign values based on a condition. |
| 14 | c) int x = (y == 5) ? 10 : 20; |
| 15 | a) Correct |
| 16 | a) It is a one-line if-else statement. |
| 17 | c) The right-hand side of the operator is executed. |
| 18 | c) int result = condition ? value : value; |
| 19 | a) return (x > 10) ? 100 : 200; |
| 20 | d) Defining a method signature |
| 21 | c) do-while loop |
| 22 | a) for (initialization; condition; increment) {} |
| 23 | a) 012 |
| 24 | a) while (condition) {} |
| 25 | b) 0 1 2 3 4 |
| 26 | c) do-while loop |
| 27 | c) break |
| 28 | a) It is best used when the number of iterations is known. |
| 29 | a) 01 |
| 30 | b) It is guaranteed to execute the code block at least once. |