Monday, April 1, 2019

Java Scanner Class

I am writing a program that should close the console if the user input the String "end'.
The program always performs the else loop even if the user inputs "end". I'm wondering why the program is not getting into the if part of the loop and shutting down.



Scanner scan = new Scanner(System.in);

while(true)
{
String num = scan.nextLine();

if(num == "end")
{
System.exit(0);
}
else
{

System.out.println("hi");
}
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...