Question: Java Scanner and While loop question I try to prompt user to enter a postive number and if the user's input is negative, there should

Java Scanner and While loop question

I try to prompt user to enter a postive number and if the user's input is negative, there should be a message saying enter a positive number. otherwise if user enters "quit" the loop should break.

So I use scanner method nextLine to read what's user's input and cast it into double if user enters number. However, I might've done it wrong as I keep getting an error message. Also should I put another while loop within the while loop? like what I've done below.

Java Scanner and While loop question I try to prompt user to

enter a postive number and if the user's input is negative, there

Library/Java/Javavirtua LMachines/jdkT.8.0 161.3ak/Contents/Home/bin/java .. Enter a positive number; [type quit to exitl quit Exception in thread "main" java. lang.NumberFormatException: For input string: "quit" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimaL.java:110) at java. Lang.Double. parseDouble (Double.iava:538) at Random.main(Random.java: 10) Process finished with exit code 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!