Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
public static void main(String[] args) {
int code = 404;
int n = Integer.parseInt(code);
System.out.println(n);
}
}
- A 404 is not valid
- B parseInt takes a String, not an int; the value is already an int (use String.valueOf to convert the other way) Correct
- C parseInt must be called on an object
- D n must be Integer
Correct Answer: Option B
javac: "incompatible types: int cannot be converted to String".
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!