Hello everyone! I'm currently having a problem with my program it doesn't loop properly please help me with it. The code is below. Thanks in advance!
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.*;
public class Wewe{
public static void main(String[]args){
Scanner inp = new Scanner(System.in);
boolean tryAgain;
do{
System.out.print("\nInput username: ");
String user = inp.nextLine();
System.out.print("\nInput password: ");
String pass = inp.nextLine();
if(user.equals("admin") && pass.equals("admin")){
System.out.print("Success!");
tryAgain = true;
}
if(user!="admin" && pass!="admin"){
JOptionPane.showMessageDialog(null, "Try again! Invalid username or password!","Error Logging-In", JOptionPane.ERROR_MESSAGE);
tryAgain = false;
}
}while(tryAgain = true);
}
}
What I want to happen is that once the user entered wrong username or password the program will then loop. But if the user entered the correct username or password, it wont loop asking the user for the correct one.