-1

i got a little problem with my code. When i write "exit" still shows statement "Unknown command" and i want to show "Bye". Can you help me?

import java.util.Scanner;

public class Hello{
    public static void main(String[] args){
        Scanner odczyt = new Scanner(System.in);
        String word;

        do{
            word = odczyt.nextLine();
            System.out.println("Unknown command");
        }
        while(word!="exit");
            System.out.println("Bye");
    }
}
Ernest
  • 33
  • 3

1 Answers1

0

"Unknown command" will always be printed. Besides that you shouldn't use = to compare Strings. You should use .equals() or .equalsIgnoreCase().

brso05
  • 13,142
  • 2
  • 21
  • 40