This program splits a list of strings to line by line. I want to stop/terminate the program after "halted" has been entered. But now it only terminates when "halted" is entered alone and not when it's in a list of strings. Any help is greatly appreciated:)
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter words ");
while (true) {
String userText = scanner.nextLine();
if (userText.equals("halted")) {
break;
}
else {
String[] pieces = userText.split(" ");
for (int i = 0; i < pieces.length; i++) {
System.out.println(pieces[i]);
if (pieces[i].equals("halted")) {
System.out.println(" Stop Program...");
break;
}
}
}
}
}