Section 3.14 Check Point Questions4 questions
3.14.1
Suppose that, when you run the following program, you enter the input 2 3 6 from the console. What is the output?
public class Test { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); double x = input.nextDouble(); double y = input.nextDouble(); double z = input.nextDouble(); System.out.println((x < y && y < z) ? "sorted" : "not sorted"); } }
3.14.2
Rewrite the following if statements using the conditional operator.
if (ages >= 16) ticketPrice = 20; else ticketPrice = 10;
3.14.3
Rewrite the following conditional expressions using if-else statements.
(a) score = (x > 10) ? 3 * scale : 4 * scale; (b) tax = (income > 10000) ? income * 0.2 : income * 0.17 + 1000; (c) System.out.println((number % 3 == 0) ? i : j);
3.14.4
Write conditional expression that returns -1 or 1 randomly.