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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...