Noii Rymnd Noii Rymnd - 1 year ago 58
Java Question

Compiler error with Integer.parseInt()

I am getting a compiler error with this code.

case 1:
System.out.printf ("Enter num1: ");
num1 = Integer.parseInt();

System.out.printf ("Enter num2: ");
num2 = Integer.parseInt();

So the
num1 = Integer.parseInt();
has an error.

Answer Source

Integer JavaDoc - Integer.ParseInt( String s ); Which parses an integer from a passed string. You are not passing the required parameters, hence the compilation error.


String example = "32";
int parsed = Integer.parseInt(example);

What you want to do, is to read the string from the reader, and pass it into Integer#parseInt. The Integer class is in no way, shape or form, connected to neither the Scanner or BufferedReader.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download