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
5 Respostas
+ 2
Hello Carl Jhon Pagayunan
Please show us your attempt so that we can help you.
+ 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 :)
+ 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
}
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!");
}
}
}
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