2
/* Make an algorithm that checks the login and password entered by user is correct. The algorithm must request from the user: login and password, and check on a set of 3 stored information variables. If the user provides the correct data, the algorithm should print a message from "Login and password correct", otherwise "Invalid login or password". The algorithm will be completed if the user hits the information or misses 3 times. */
import java.util.Scanner;
public class exercicio5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String login = "admin" ; String senha="1234"; int count = 1; String digite;
while (count<=3) {
System.out.print ("Digite o login:");
digite = sc.next();
if (login==digite) {
System.out.print ("Digite a senha:\n");
digite = sc.next();
if (digite==senha){
count=3;
}
} else {
System.out.print("Login invalido.\n\n");
}
count = count+1;
}
System.out.print("Concluido");
}
}
Possible duplicate of How to compare Strings in Java?
– hkotsubo