read double, but if blank input do something else[java]
I want to ask the user for a double value and read it in using nextDouble() method in the Scanner class from the keyboard.. but if the user just hits enter I want to register that aswell.. how can I do this as easy as possible?
Hmm, I don't know much about Java, but Google gave me this(http://www.java2s.com/Code/JavaAPI/java.util/ScannernextDouble.htm):
So try Scanner.hasNextDouble to check whether the input is a double or something else, or nothing (Scanner.hasNext).
...else if (src.hasNextDouble()) { d = src.nextDouble();...
So try Scanner.hasNextDouble to check whether the input is a double or something else, or nothing (Scanner.hasNext).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement