Below is a simple program that I wrote that will ask for a password. If I enter the incorrect password I am prompted with "Password incorrect would you like to try again?", and if I say no or anything else that doesn't begin with a 'y', it will terminate the program. The problem is, if I enter the correct password which is "Noah" it says "Password correct" and it loops back to "Enter password" again. How can I make this program terminate after I enter the correct password? Thank you.
import java.util.Scanner;
public class methods
{
public static void main (String [] args)
{
Scanner sc = new Scanner(System.in);
String response = "yes";
System.out.println("Enter password:");
while(response.charAt(0)=='y')
{
String input = sc.nextLine();
if(input.equalsIgnoreCase("Noah")==true)
{
System.out.println("Password correct");
}
else if(input.equalsIgnoreCase("Noah")==false)
{
System.out.println("Password incorrect, would you like to try again?");
response = sc.nextLine();
}
}
}
}
input.equalsIgnoreCase("Noah")==trueRemove the==true, I get angry when I see this.