What is the output of the following, and why? int x = 2; switch (x) { case 1: System.out.print("A"); case 2: System.out.print("B"); case 3: System.out.print("C"); }
Conditional Constructs
Original Khojo Papers practice question — not from a past board paper.
if (a >= b && a >= c) System.out.println(a); else if (b >= a && b >= c) System.out.println(b); else System.out.println(c);
No citable source has been recorded for this record. Treat it as practice material, not as fact.
Using >= rather than > means equal values do not fall through to the wrong branch.
From the same topic and chapter, at a similar level.
What is the output of the following, and why? int x = 2; switch (x) { case 1: System.out.print("A"); case 2: System.out.print("B"); case 3: System.out.print("C"); }
Conditional Constructs
Write a Java program segment using a switch to print the name of the day for a number from 1 to 7.
Conditional Constructs
Write a Java program segment that reads an integer and prints whether it is positive, negative or zero.
Conditional Constructs
State three differences between the if-else construct and the switch-case construct.
Conditional Constructs
Explain the ternary operator in Java and rewrite "if (a > b) max = a; else max = b;" using it.
Operators and Expressions in Java
What is the output of: String s = "Examination"; System.out.println(s.length() + " " + s.substring(0, 4) + " " + s.toUpperCase().charAt(2));
String Handling