为什么我会得到无限循环

lub*_*aaa 2 java infinite-loop

public class Spreadsheet {

    public static final int row = 10;
    public static final int column = 7;
    static Cell[][] data;

    public static void print() {
        data = new Cell[column][row];
        for(int i = 0; i < row; i++) {
                for(int j = 0; j < column; j++) {
                    System.out.printf("%13s","|");
                }
                    System.out.println();
                for(int j = 0; j < column; j++) {
                    for(int k = 0; k < 12; k++) {
                        System.out.print("_");
                    }
                        System.out.print("+");
                }
                    System.out.println();
            }
    }
Run Code Online (Sandbox Code Playgroud)

这应该打印出一个10x7的电子表格,但它没有这样做.这里似乎是一个无限循环错误.救命?

Rob*_*sen 5

您只需要一次用户输入,然后继续重复使用相同的输入.您可以修复如下:

while(input.hasNext()) {
    String userInput = input.nextLine();

    if (!userInput.equalsIgnoreCase("exit")) {
        commandLoop(userInput);
    }
}
Run Code Online (Sandbox Code Playgroud)

你也可以在条件中填写条件的赋值和评估while,但我发现它的可读性较差.