+ 1

Java 18.2 safety is first

Password 8819. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password; do { System.out.println("Write password"); password = read.nextInt(); if (password == 8819){ break; }else if ( password != 8819){ System.out.println("Write password"); } } while ( password == 8819); } } And I’m always getting the troubles with 4th test. Idk what the ??

11th Sep 2021, 4:02 AM
Filin Oleg
5 Respuestas
+ 4
Filin Oleg do { password = read.nextInt(); //Print } while (password != 8819); Just do like this. You have unnecessary checking instead you can just check in while case. That's what the actual use of do while loop.
11th Sep 2021, 4:06 AM
A͢J
A͢J - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password; do{ System.out.println("Write password"); password = read.nextInt(); //System.out.println(password); if ( password == 8819){ break; }else if (password != 8819){ // System.out.println("Write password"); } }while (password != 8819); } }
11th Sep 2021, 4:20 AM
Filin Oleg
0
At first i thought that while is going to loop while result is negative.
11th Sep 2021, 4:21 AM
Filin Oleg
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password; do{ int x = 1; password = read.nextInt(); System.out.println("Write password"); x++; } while (password != 8819); } }
4th Mar 2022, 2:15 AM
Madison Cormier
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password; do{ int x = 1; password = read.nextInt(); System.out.println("Write password"); x++; } while (password != 8819); } }
4th Mar 2022, 2:15 AM
Madison Cormier