while loop / string input not working java
Posted
by
Mikeecb
on Stack Overflow
See other posts from Stack Overflow
or by Mikeecb
Published on 2012-10-13T09:31:01Z
Indexed on
2012/10/13
9:37 UTC
Read the original article
Hit count: 183
I have looked online and all of the tutorials / questions have pointed me to this. I can't see why this isn't working. Any help would be much appreciated. Thanks
import java.util.*;
public class test {
static Scanner userInput = new Scanner(System.in);
public static void main(String[] args) {
String textEntered = userInput.next();
if (textEntered == "hello") {
System.out.println("Hello to you too!");
}
}
}
I enter "hello" but nothing is printed. Also I have tried next() and nextLine();
© Stack Overflow or respective owner