Question 19
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
System.out.println(Integer.compare(5, 9) + " " + Integer.max(5, 9) + " " + Integer.sum(5, 9) + " " + Double.compare(2.5, 2.5) + " " + Character.compare('b', 'a') + " " + Integer.signum(-42) + " " + Long.numberOfTrailingZeros(8));
}
}
- A -1 9 14 0 1 -1 3 Correct
- B -4 9 14 0 1 -1 3
- C -1 9 14 0 1 -42 3
- D -1 5 14 1 1 -1 8
Correct Answer: Option A
Integer.compare returns -1, 0 or 1; Character.compare returns the difference (1 here). 8 is 1000 in binary – three trailing zeros.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!