I'm trying to understand how this solution works with a validator (nested in 'do' while). I just can not understand the order of execution of the code.
I do not understand why age = s.nextInt (); goes below the loop. In what order here what is performed?
void setAge() { Scanner s = new Scanner(System.in); do { while (!s.hasNextInt()) { System.out.println("Некорректное значение, попробуйте еще раз: "); s.next(); } age = s.nextInt(); System.out.println("Устанавливается возраст..."); if (age < 0) { System.out.println("Некорректное значение, введите еще раз: "); } if (age > 150) { System.out.println("Слишком большое значение, введите еще раз: "); } } while (age < 0 || age > 150); System.out.println("Вы установили возраст - " + this.age); }