I had a similar code to this using numbers, and it worked perfectly. This however keeps underlining the word else and I don't know why. I am just playing around with java trying to understand a few principles.
I want to program to reply one of two statements depending on input. Also, where it says if (input1 == "Hello");
, I wanted to put if (input1 == "Hello" || "hello");
to accept lowercase too, but that showed errors too.
Just to be clear, if i remove the else clause, my program runs and both statements are printed!
import java.util.Scanner;
public class Input
{
public static void main(String[] args)
{
System.out.println("Hello there!");
Scanner Scan = new Scanner (System.in);
String input1 = Scan.nextLine();
Scan.close();
if (input1 == "Hello");
{
System.out.println("How are you?");
}
else
System.out.println("How rude, you didn't even say Hello!");
break;
}
}
}