我的"for循环"的问题 - Java

3.1*_*per 2 java for-loop

我一直在尝试创建一个for loop打印任意两个输入之间的所有整数integers.

例如:

如果我输入1和4,它应该打印1,2,3,4.

但是,我当前的代码只打印最终输入.(标记为"结束"的那个)

什么可以用我的代码?请注意,if语句会检查以确保输入有效.

{
    int start = Integer.parseInt(startingInput.getText());
    int end = Integer.parseInt(endingInput.getText());

    if (start >= end) {
       hintLabel.setText("Please input valid numbers"); 
    }
    else {
        for (int count = start; count <= end; count++) {
            outputArea.setText(count + ", ");
        }
    }
}                                           
Run Code Online (Sandbox Code Playgroud)

Era*_*ran 7

您正在将输出打印到某个UI组件,并且您将继续覆盖以前的值:

outputArea.setText(count + ", ");
Run Code Online (Sandbox Code Playgroud)

你需要类似的东西(不确定确切的方法调用,因为我不知道它的类型outputArea):

outputArea.setText(outputArea.getText () + count + ", ");
Run Code Online (Sandbox Code Playgroud)