1
My problem is this:
package com.vreawillsaveyou01;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float number = scanner.nextFloat();
System.out.println(number);
}
}
When I type a floating point number, using the point as decimal separator (for example, 3.92
), the program gives the following error:
Exception in thread "main" java.util.InputMismatchException
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextFloat(Scanner.java:2496)
at com.vreawillsaveyou01.Main.main(Main.java:8)
What I’m doing wrong and how can I fix it?
the code seems correct, is typing the number with semicolon?
– Ricardo Pontual
I’m typing with dot
– Bernardo Martins
@Ricardopunctual for example when I put 3.92 gives me that mistake
– Bernardo Martins