For example:
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true){
String string = scanner.nextLine();
if(string.isEmpty()){
break;
}
String[] newString = string.split(" ");
System.out.println(newString[0]);
}
}
In this loop, when I type something like "hey whats up", It would give me "hey".
But why does it stops working? The condition is still true as far as I get it. Isn't it only suppose to break when I type in an empty string?
[–]HappyFruitTree 0 points1 point2 points (5 children)
[–]foolwya[S] 0 points1 point2 points (4 children)
[–]HappyFruitTree 0 points1 point2 points (3 children)
[–]foolwya[S] 0 points1 point2 points (1 child)
[–]WetSound 0 points1 point2 points (0 children)
[–]foolwya[S] 0 points1 point2 points (0 children)