I have a pretty stupid question, let me say, but I do not remember what I should do to be correct. I should create a program that reads an integer and prints on the screen.
Here's what I have:
import java.io.IOException;
import java.util.Scanner;
public class Real {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
double real;
Scanner le = new Scanner(System.in);
System.out.println("Digite um numero real");
real = le.nextDouble();
System.out.println("O numero digitado é:" +real);
le.close();
}
}
I can type the number (I typed for example 2.35) but it gives the following error:
Digite um numero real 3.2 Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextDouble(Unknown Source) at Real.main(Real.java:14)
Help me. I should not use if
, else
, nothing. It's a basic exercise.