K
K
Kirill Bazhenov2017-10-08 15:39:21
Java
Kirill Bazhenov, 2017-10-08 15:39:21

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

1 answer(s)
D
D3lphi, 2017-10-08
@D3lphi

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());

Or like this:
System.out.println("Введите данные: ");
while(!input()) {
     System.out.println("Ошибочный ввод. Попробуйте еще раз: ");
}

private boolean input()
{
    // Считываем данные, проверяем их на валидность и возвращаем true - если ввод валиден и false - если невалиден.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question