Course Solutions Uncategorized (Solved) : Java Scanner Loop Question Try Prompt User Enter Postive Number User S Input Negative Mess Q26700837 . . . .

(Solved) : Java Scanner Loop Question Try Prompt User Enter Postive Number User S Input Negative Mess Q26700837 . . . .

 

Java Scanner and While loop question

I try to prompt user to enter a postive number and if the user’sinput is negative, there should be a message saying enter apositive number. otherwise if user enters “quit” the loop shouldbreak.

So I use scanner method nextLine to read what’s user’s input andcast it into double if user enters number. However, I might’ve doneit wrong as I keep getting an error message. Also should I putanother while loop within the while loop? like what I’ve donebelow.

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

Library/Java/Javavirtua

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post