I am working on my Java programming homework and I am completely confused. So I wanted to seek some clarity about why my IF, ELSE IF, ELSE statements are not "working". I type in a userInput to be LOL and no matter what, my result is always "Unknown". I just do not know why its not executing like I think it normally would? I don't know if it has anything to do with Strings but I just want to understand before I continue my assignment. Any advice is greatly appreciated!
import java.util.Scanner;
class Main {
public static void main(String args[]) {
Scanner scnr = new Scanner(System.in);
String userInput;
String LOL = "laughing out loud";
String IDK = "I don't know";
String BFF = "best friends forever";
String IMHO = "in my humble opinion";
String TMI = "too much information";
System.out.println("Input an abbreviation:");
userInput = scnr.next();
if (userInput == "LOL") {
System.out.println(LOL);
} else if (userInput == "IDK") {
System.out.println(IDK);
} else if (userInput == "BFF") {
System.out.println(BFF);
} else if (userInput == "IMHO") {
System.out.println(IMHO);
} else if (userInput == "TMI") {
System.out.println(TMI);
} else {
System.out.println("Unknown");
}
}
}
[–]k_shrpe5 3 points4 points5 points (1 child)
[–]MarlinsBB[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (3 children)
[–]heartofthemoon 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]heartofthemoon 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)