+ 1
Need help Java
I’m having trouble getting a program that says a simple, “hi” to you if you say hello to work. Keep in mind my coding knowledge is abysmal except basic Lua. import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner test = new Scanner(System.in); System.out.println(test.nextLine()); if (test = "hello"); System.out.println("hi"); } }
1 Antwort
+ 2
To check for String equality in Java you need to use the equals() method not ==.
if (test.equals("hello")
Also, you're not setting the input value to the test variable.
Scanner scanner = new Scanner(System.in);
String test = scanner.nextLine();