java - How do I get this try catch to loop until it no longer gets an error? -


I have a try block that is checking whether the input is from the scanner or not. But instead of loop it twice and asks how many people have to send .. Then say error: no number. Actually without prompting the user to enter a different number

  int peopleToSend = 0; // I tried to catch one ... but it is not working for whom I was planning for ... while (locosed & lt; 1 || people suspect & gt; people olive ()) {try { system.out.print ("\" How many people do you want to send out? 1 - "+ PeopleAlive () +": "); PeopleToSend = scan.nextInt (); } Hold (exception e) {System.out.println ("Error: no number."); }}   

An example of output when entering someone other than an int.

  How many people do you want to send? 1 - 22: Error: No number How many people do you want to send out? 1 - 22: Error: No number How many people do you want to send out? 1 - 22: Error: No number How many people do you want to send out? 1 - 22: Error: No number * Loops forever *    

One Add a scan. Nxt (); After the statement error:

  hold (exception e) {System.out.println ("Error: no number."); Scan.next (); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -