I'm trying to figure out why my function isn't working as it should. The code is fairly basic and self explanatory. Here is the function:
public static void Greet(){
System.out.println("Hello, what is your name? ");
name = scan.nextLine();
do{
System.out.println("Would you like to order some coffee, " + name + "? (y/n) ");
input = scan.nextLine();
if(input == "y"){
System.out.println("Great! Let's get started.");
break;
}
else if(input == "n"){
System.out.println("Come back next time, " + name + ".");
System.exit(0);
}
else{
System.out.println("Invalid response. Try again.");
}
}
while(true);
}
Basically, regardless of what I enter as "input" on line 5, the function will treat it as if I hadn't entered a 'y' or 'n', it just constantly loops the while(true) and printing "Invalid response. Try again." I have no idea why my if/else statements aren't working correctly. Any help would be appreciated, thanks!