Question 18
Back to Exercise
What is the output of the following Java program?
public class Main {
public static void main(String[] args) {
String a = "25", b = "17";
System.out.println(a + b);
System.out.println(Integer.parseInt(a) + Integer.parseInt(b));
System.out.println(Integer.parseInt("ff", 16) + " " + Integer.toBinaryString(10) + " " + Double.parseDouble("1e3"));
try {
Integer.parseInt(" 42");
} catch (NumberFormatException e) {
System.out.println("bad number");
}
}
}
- A 2517 42 255 1010 1000.0 bad number Correct
- B 42 42 255 1010 1000.0 bad number
- C 2517 42 255 1010 1e3 bad number
- D 2517 42 255 1010 1000.0 42
Correct Answer: Option A
+ on Strings concatenates. parseInt does not accept spaces – trim or strip input first.
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!