System.out.print("Enter digit: "); Scanner s1 = new Scanner(System.in); int n1 = s1.nextInt(); if (n1 == 1) { System.out.print("1234555555"); } else { System.out.print("error"); } 

I need to, if I entered 123656543544, then write type Error, enter again ...

  • Do you know about the cycles? - Mikhail Vaysman
  • @MikhailVaysman and where are the cycles? - user240095
  • one
    Moreover, the word "bye" implies a cycle - vp_arth

1 answer 1

 **Пока** считанная строка не равна кодовому слову Выводить: Ошибка, попробуйте ещё Вывести: ок 
 Scanner s1 = new Scanner(System.in); while (!s1.nextLine().equals("Password")) { System.out.println("Error, try again"); } System.out.println("ok"); 

 Scanner s1 = new Scanner(System.in); String inp; do { inp = s1.nextLine(); if (inp.equals("exit") || inp.equals("quit")) { System.exit(1); } } while (!inp.equals("Password")); System.out.println("ok"); 
  • how do I write type if (s1 == 7) Then togad (in c #) Environment.Exit (-1); How can I rewrite this line to java? - user240095
  • Why does he stress Exit to me? The method Exit (int) is undefined for the type Environment - user240095
  • If in Main, you can simply return 1; - vp_arth
  • does not go wrong and wrong - user240095
  • it worked only like this: Scanner s1 = new Scanner(System.in); if (!s1.nextLine().equals("7")) { System.exit(-1); } else { System.out.print("error"); s1.close(); } Scanner s1 = new Scanner(System.in); if (!s1.nextLine().equals("7")) { System.exit(-1); } else { System.out.print("error"); s1.close(); } Scanner s1 = new Scanner(System.in); if (!s1.nextLine().equals("7")) { System.exit(-1); } else { System.out.print("error"); s1.close(); } - user240095