Safety first - java do while loop challenge | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 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); } }

10th Sep 2021, 5:55 AM
Amarjot
12 Antworten
+ 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.
10th Sep 2021, 6:28 AM
Coding Cat
Coding Cat - avatar
+ 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..
10th Sep 2021, 6:40 AM
Rupali Haldiya
Rupali Haldiya - avatar
+ 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 :( :( :( :( :( :( :( :( .....!!
13th Oct 2022, 3:23 AM
Jett
Jett - avatar
+ 1
rupali very nice. But I wont give a ready to use solution to self lerners on SL. 😞
10th Sep 2021, 6:53 AM
Coding Cat
Coding Cat - avatar
+ 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
18th Jun 2022, 7:42 AM
Sachini Anjana
Sachini Anjana - avatar
0
Kindly share the question too... bcz I don't have enough bits to unlock this challenge 😅
10th Sep 2021, 6:18 AM
Rupali Haldiya
Rupali Haldiya - avatar
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
10th Sep 2021, 6:21 AM
Amarjot
0
Or maybe first print output, then take input, then check the condition. I think, that makes more sense.
10th Sep 2021, 6:33 AM
Coding Cat
Coding Cat - avatar
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.
10th Sep 2021, 6:55 AM
Amarjot
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.
28th Apr 2022, 2:12 PM
Mensah Jonathan
Mensah Jonathan - avatar
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); } }
15th Nov 2022, 7:43 AM
Pooja Patel
Pooja Patel - avatar
- 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.
10th Sep 2021, 6:19 AM
Coding Cat
Coding Cat - avatar