This question already has an answer here:
- How do I compare strings in Java? 23 answers
I tried to use the Scanner in connection with the if statement instead of switch, but it doesn't work as I planned, it should return Bye, when I type in Hi, but instead it does nothing
Here is the code :
import java.util.Scanner;
public class MainClass {
private static Scanner scanner;
public static void main (String[] args) {
scanner = new Scanner(System.in);
String Line = scanner.next();
if(Line == "Hi") {
System.out.println("Bye");
}
}
}
Aucun commentaire:
Enregistrer un commentaire