Hi guys can you teach me how to login username and password log in attempts if type wrong he will get attempts until 3 pls codes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hi guys can you teach me how to login username and password log in attempts if type wrong he will get attempts until 3 pls codes

8th Mar 2021, 3:30 PM
Carl Jhon Pagayunan
Carl Jhon Pagayunan - avatar
5 Answers
+ 2
Hello Carl Jhon Pagayunan Please show us your attempt so that we can help you.
8th Mar 2021, 3:47 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
https://code.sololearn.com/c4Upa1Zg7V9l/?ref=app Hi Carl Jhon Pagayunan I hope this helps you. You needed a while loop that runs 3 times. Every time the user enters wrong details, you increment the value of the loop counter and it asks for the password and name once again. And btw, Denise Roßberg is not a 'sir', she's a 'ma'am'. Happy coding :)
8th Mar 2021, 4:07 PM
Soumik
Soumik - avatar
+ 1
Carl Jhon Pagayunan You can use the code playground here on sololearn. If you open the app you see at the bottom this tap: {} Click on it, then click on the plus sign and choose java. But here on sololearn you need to enter all the values at the beginning. Step by step is unfortunately not working here. About your code: That looks good. Now you need a counter and a loop. And I would use a boolean variable. int counter = 0; boolean correctLogin = false; while(counter < 3){ if("Cj".equals(Username) && "Pagayinan".equals(Password)){ correctLogin = true; break; //ends the loop } counter++; } Now you just need to check if correctLogin is true or false. if(correctLogin){ //print }else{ //print }
8th Mar 2021, 4:20 PM
Denise Roßberg
Denise Roßberg - avatar
0
Denise Roßberg sir this is my attempt i want to repeat the string username and password until 3 times if they put wrong username or password. My Code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter Username"); String Username = scanner.nextLine(); System.out.println("Enter Password"); String Password = scanner.nextLine(); if("Cj".equals(Username) && "Pagayunan".equals(Password)) { System.out.println("Log in successful!"); }else{ System.out.println("Log in error!"); } } }
8th Mar 2021, 3:51 PM
Carl Jhon Pagayunan
Carl Jhon Pagayunan - avatar
0
I code this in dcoder because i am beginner here i dont know.how to code here. I hope you help me 🥺 Denise Roßberg
8th Mar 2021, 3:52 PM
Carl Jhon Pagayunan
Carl Jhon Pagayunan - avatar