java - while() loop for user input -


I'm working on setting up a 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 ();}}}}  

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:

  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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -