+ 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 ??
5 Réponses
+ 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.
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);
}
}
0
At first i thought that while is going to loop while result is negative.
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);
}
}
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);
}
}