Hey everyone,
my if-statements are working as expected. Actually, they are not working at all. The syntax is right but they are never run. The program terminates before it runs them.
public static void main (String args[]){
Scanner input = new Scanner(System.in);
Display fName = new Display(); // creating a new obj called fName
System.out.println("Enter your first name: ");
String name = input.nextLine();
fName.greeting(name);
Display howToDo = new Display();
System.out.println("How are you," + name + " ?");
String name1 = input.nextLine();
if (name1 == "good"){
System.out.println("We know that you're good. Keep it up!");
}else if (name1 == "fine") {
System.out.println("We know that you're fine.");
}else if(name1 == "ok"){
System.out.println("We know that you're ok. Improve it lol!");
}
when I use defualt at the end of this blocks, the default condition works.
I tried using switch(name1) --> was giving me errors because of data type.
Thanks,