Write a Java program segment that reads three numbers and prints the largest.
Conditional Constructs
Original Khojo Papers practice question — not from a past board paper.
if-else can test any boolean condition, including ranges and combinations, while switch tests only equality against constant values. switch works with int, char, byte, short, String and enum, but not with float, double or boolean. A switch without a break falls through to the following cases, which if-else never does.
No citable source has been recorded for this record. Treat it as practice material, not as fact.
switch is usually clearer when there are many equality tests on one variable.
From the same topic and chapter, at a similar level.
Write a Java program segment that reads three numbers and prints the largest.
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
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
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