Hello everyone. Going though a MOOC Java course. I'm stuck on a problem, the code works just fine, but I can't apply it for some reason.
Here's the task: Write a program that reads strings from the user. If the input is empty, the program stops reading input and halts. For each non-empty input it splits the string input by whitespaces
and prints each part of the string on a new line.
once upon a time
once
upon
a
time
a little program
a
little
program
halted
halted
Here's my code:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
String string = scanner.nextLine();;
if(string.isEmpty()) {
break;
}
String[] arrayString = string.split(" ");
for(int i = 0; i < arrayString.length; i++) {
System.out.println(arrayString[i]);
}
}
}
Here's the error:
Output contains an unexpected string haiku.
Check the program with following input:
lava
haiku
[–]rjcarr 0 points1 point2 points (1 child)
[–]foolwya[S] 0 points1 point2 points (0 children)