- 3
Safety first - java do while loop challenge
I am currently stuck on the do while challenge for module 2 of java. I am unable to output just one result when a single input value has been given. Below is the code that i have written which only passes for inputs greater than 2. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner read = new Scanner(System.in); int password = 1; do{ System.out.println("Write password"); password ++; }while(password < 3); } }
13 Respostas
+ 4
- First start the do loop.
- Take the input to the
variable password
- print the output:
"Write password"
- Check while condion:
while (password != 8819)
And I think that's it.
+ 3
Amarjot
I hope it will pass all test cases đ
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int password;
do{
password = read.nextInt();
System.out.println("Write password");
}while(password != 8819);
}
}
Coding Cat [Mouse searching] it's exactly what I thought..
+ 2
This is LITERALLY the HARDEST Gosh Dang Coding Language I've ever even SEEN.... NONE of it makes sense to me and IDK if it EVER WILL..... I mean ugh I can understand RUBY and KOTLIN A LOT BETTER than this...... This is VERY DIFFICULT :( :( :( :( :( :( :( :( .....!!
+ 1
rupali very nice. But I wont give a ready to use solution to self lerners on SL. đ
+ 1
//Java do while challenge - Safety first
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();
}
while(password !=8819);
}
}
//Good luck everyone
0
Kindly share the question too... bcz I don't have enough bits to unlock this challenge đ
0
Yeh sorry that is the problem Thank you Coding Cat. Below are the sample inputs and outputs.
Sample Input
3332
8819
Sample Output
Write password
Write password
0
Or maybe first print output, then take input, then check the condition. I think, that makes more sense.
0
Thanks Rupali it worked. I understand now what I was doing wrong. Should have had the program read the next lines in the do parentheses and the while loop being the original condition of it not equalling to 8819.
0
A board game company creates new board games every year. While all the games have different rules, they also are all similar in that they each have a name and a play() method.
We need to create 3 different games - Monopoly, Chess and Battleships. In the play() method Monopoly should print âBuy all property.â, Battleships - âSink all ships.â, and Chess - âKill the enemy king.â
Complete the code by implementing the getName() and play() methods inherited from abstract Game class.
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int password;
do{
password = read.nextInt();
System.out.println("Write password");
}while(password != 8819);
}
}
0
Here's the code which satisfies all the test cases :))
" int password;
do{
password=read.nextInt();
System.out.println("Write password");
password++;
}
while(password<=8819); "
- 1
You're creating a bank security system. The user must insert the correct password in order to access payments.
The password is 8819.
Task
Write a program that will continuously take a password as input and output Write password, until the client inserts the correct password.