import java.util.Scanner; public class Test { public static void act() { String phrase; Scanner sc = new Scanner(System.in); System.out.println("Да или нет?"); String ans[] = {"да", "нет"}; phrase = sc.next(); phrase = phrase.toLowerCase(); //конвертируем всю строку в строчные буквы boolean a = phrase.equals(ans[0]); boolean b = phrase.equals(ans[1]); if (a || b) { System.out.println("На что ты ответил то?!"); } else { while (!a || !b) { System.out.println("Я просто просил ответить 'да' или 'нет', не более!"); phrase = sc.next(); a = phrase.equals(ans[0]); b = phrase.equals(ans[1]); System.out.println(a); System.out.println(b); } } } } Why, if it comes to a cycle, it runs forever. Help me fix it. It is not clear why the value of a and b does not change to false .
while(sc.hasNext()) {...}- And