The code doesn't exit after I type "stop" - for some reason. Why? Step-by-step debugging shows that after I enter "stop" it's value consists of exactly 's','t','o','p' without any line breaks, etc. - however, the code still goesn't exit. Could anyone tell why, please?
import java.util.Scanner;
public class Application {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// asking username
System.out.print("Username: ");
String username = input.nextLine();
String inpText;
do {
System.out.print(username + "$: ");
inpText = input.nextLine();
System.out.print("\n");
// analyzing
switch (inpText) {
case "start":
System.out.println("> Machine started!");
break;
case "stop":
System.out.println("> Stopped!");
break;
default:
System.out.println("> Command not recognized");
}
} while (inpText != "stop");
System.out.println("Bye!..");
}
}