Thursday, October 31, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...