java - I can't understand how to reset this loop/scanner -
My program is supposed to be prompted by the user to enter the exam score related to how many tests were taken It works fine, but when a user enters the negative exam score, he should re-enter the three examinations. My program does not save any exams which was not negative, when you enter three examinations, it uses only that three are required to complete or how many are looking for it. Maybe something is so easy that I am missing because I'm new to this. I think a question given below is enough for a reply, if I have a big problem then I hope.
System.out.print ("Enter the Exam Score:"); For (int y = 1; y and lt; = numberofexams; y ++) {test = NumScanner.nextDouble (); While (exams & lt; 0) {NumScanner.nextLine (); System.out.print ("Invalid exam score, re-score:"); Exam = NumScanner.nextDouble (); } System.out.println (); If break (y & gt; numphxam); Yoga + = exams; // test average sum2 + = exams; // class average} // number of exams
I do not want to see why you Should while loop, and why do you scan nextLine () ? Try this code: System.out.print ("Enter the exam score:"); For (int y = 1; y and lt; = numberofexams; y ++) {test = NumScanner.nextDouble (); If (exams & lt; 0) {y = 1; to continue; } System.out.println (); If break (y & gt; numphxam); Yoga + = exams; // test average sum2 + = exams; // class average} // number of exams
Comments
Post a Comment