jeudi 20 octobre 2016

New to Java - tried out the Scanner, but didn't worked as planned [duplicate]

This question already has an answer here:

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