Answer the question
In order to leave comments, you need to log in
If the user has entered incorrect data, how can I ask him to enter it again?
If the user has entered incorrect data, how can I ask him to enter it again?
Answer the question
In order to leave comments, you need to log in
Console application? You start the loop and exit it only if the data is correct. You need a do-while/while loop.
Something like this:
do {
System.out.println("Введите данные: ");
} while(!input());
System.out.println("Введите данные: ");
while(!input()) {
System.out.println("Ошибочный ввод. Попробуйте еще раз: ");
}
private boolean input()
{
// Считываем данные, проверяем их на валидность и возвращаем true - если ввод валиден и false - если невалиден.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question