Sign in to follow this  
Nanook

read double, but if blank input do something else[java]

Recommended Posts

Nanook    537
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?

Share this post


Link to post
Share on other sites
Nanook    537
Yeah, well.. I dont think that would work from the keyboard though? I came up with a way to do it though.. I read in a nextLine instead.. (String) then checked if that was empty and then if it wasn't I tried to parse it to a double..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this