LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Find the Error · Question 10

Error: passing an int to Integer.parseInt Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links