Answer the question
In order to leave comments, you need to log in
How does the while loop work?
Reading data from the keyboard. The loop must end when the word exit is entered.
boolean isExit = false; //объявили переменную isExit присвоили значение false
while (!isExit) //пока isExit правда, то
{
String s = bufferedReader.readLine(); // считываем с клавиатуры и передаем в переменную s
isExit = s.equals("exit"); // теперь isExit имеет значение либо true либо false. Если s = "exit", то
// isExit имеет значение true и цикл заканчивает работу.
// НЕ ПОНИМАЮ ЛОГИКИ, ведь если isExit ПРАВДА, то продолжаем
// считывать с клавиатуры, а тут наоборот, заканчивает свою работу...
System.out.println(s); // выводим строку на консоль
}
Answer the question
In order to leave comments, you need to log in
You have !isExit in your while, i.e. not isExit.
So when isExit is true then !isExit is false and aborts the while
Hello. Cool. I love it when they immediately write boolean isExit = false; and the next action while(!isExit).
Should work without problems, but you can change a little bit.
while isExit is false you meant to say, but !isExit is true.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question