我是 Java 世界的新手。我写了这个读取字符串数组的程序......当我运行它时,它永远不会停止?!我应该添加/更改什么以使其结束扫描?
import java.util.*;
public class Ex21 {
public static void main(String[] args) {
int i, n = 5;
String c;
ArrayList<String>words = new ArrayList<>();
System.out.println("Enter multi strings: ");
Scanner input = new Scanner(System.in);
boolean loop = true;
while(loop) {
words.add(input.next());
Collections.sort(words);
System.out.println("The sorted list is: " + words);
}
}
}