I have a problem with the java Scanner : I'm trying to read doubles using this code :
Scanner sc = new Scanner(System.in);
double value = sc.nextDouble();
However when the number to read is "0.0" or "0." or "0" I have the following error :
java.util.InputMismatchException: "0" is not a double
Is that the normal behaviour of the "nextDouble()" function ?
What's the easiest way to read a double without having this problem ?
Do I really need to catch the error and then try again with "netxInt()" ?
Thanks for your help.
For information I'm using the java compiler "gcj".
It's working fine with javac but with gcj (on an up-to-date ubuntu) it's not working. Details of the gcj version are provided at the bottom.
Full code :
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
double f = sc.nextDouble();
}
}
Input (on standard input) :
0.0
Output :
Exception in thread "main" java.util.InputMismatchException: "0" is not a double
*** Got java.lang.OutOfMemoryError: Cannot create additional threads while trying to print stack trace.
Result of a "gcj -v" :
COLLECT_GCC=gcj
COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5.2/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu1' --with-bugurl=file:///usr/share/doc/gcj-4.5/README.Bugs --enable-languages=c,c++,java --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=i386-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/i386-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/i386-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-time=yes --disable-libmudflap --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.5/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.5 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.5 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu1)
Same behaviour on a "gcc version 4.4.5" on an other server.