java - while() loop for user input -
I'm working on setting up a I agree I want to enter int (or integer) to the user and ask the user again and again until the user enters (or integer) enters. If so, try this: while () the user who does not enter the integer Does. However, the way I have it now, after entering the integer to the loop, the message
"Please enter integer" again prints, and then the program normally executes whether a person After entering an integer, can any method of recommending that message be reprinted? Thanks!
System.out.println ("Enter the length of the word"); If (in.hasNextInt ()) {n = in.nextInt (); } Else {while looping (in.hasNext ()) // This is I'm talking about (System.out.println ("Please enter an integer"); if (in.hasNextInt ()) {n = in.nextInt (); break;; else {string c = in.next ();}}}}
System.out.println ("Enter word length"); if (in.hasNextI nt ()) {n = in.nextInt ();} and {while (in.hasNext ()) // This is the loop I'm talking about (if.hasNextInt ()) {n = in.nextInt (); Break;; else {String c = in.next (); System.out.println ("Please enter an integer");}}} Click on
Comments
Post a Comment