Why does Java throw an error when using Scanner.nextFloat() but not Scanner.nextInt() ?
package myshit;
import java.lang.Math;
import java.util.Scanner;
public class speed2 {
public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
float number = keyboard.nextFloat();
System.out.print("Start");
}
}
Input:
2.5
Output:
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.nextFloat(Unknown Source)
at myshit.speed2.main(speed2.java:10)
But just by switching nextFloat to nextInt no error occurs:
package myshit;
import java.lang.Math;
import java.util.Scanner;
public class speed2 {
public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
int number = keyboard.nextInt();
System.out.print("Start");
}
}
input:
3
Output:
Start
What am I doing wrong?
Appears i needed to input , instead of . Seems to be because of Eclipse