Monday 7 January 2019

Scanning double with Scanner in Java from Console

I want to read a double number from standard input, but I always get this exception:




java.util.InputMismatchException





import java.util.Scanner;

public class ScanDouble {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
double d = scan.nextDouble();
System.out.println("Double: " + d);

}
}


If the input is integer it's okay, but when double, I get the exception.




Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)

at java.util.Scanner.nextDouble(Scanner.java:2413)
at ScanDouble.main(ScanDouble.java:10)


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...