0
Scanner scan = new Scanner(System.in);
        double cost = scan.nextDouble();
        System.out.println(cost);

So i try writing 7.6 and it throws and exception in main. But when i write 7,6 it's OK and it prints 7.6

I'm using eclipse as my IDE

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
MaWiWa
  • 1
  • 1

1 Answers1

2

System locale uses decimal separator ',' (on your current system), you can explicitly specify the locale the scanner should use like

Scanner scan = new Scanner(System.in);
scan.useLocale(Locale.US);
double cost = scan.nextDouble();
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249