I am unable to enter doubles value in my program from my bash terminal. Below is the code I used to figure out why it is happening.
This is my code for the test:
import java.util.*;
public class DoubleTest {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
double n = sc.nextDouble();
System.out.println(n);
}
}
With the following input 5, I get the expected results.
user $ java DoubleTest
5
5.0
Now to the interesting part. I input a Double as declared in the code, and this happens:
user $ java DoubleTest
5.0
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.nextDouble(Scanner.java:2564)
at DoubleTest.main(DoubleTest.java:6)
And when giving a value of 5,0 - this is the result:
user $ java DoubleTest
5,0
5.0
So it seems that the .
(dot) is not working, but instead ,
(comma) is.
I already checked my locale, but that shouldn't be the problem.
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"