小编use*_*231的帖子

Java:即使条件已满足,也会执行/ while循环重复

我正在尝试一个简单的do while循环,假设在输入小于1且大于1000时运行.它应该要求用户在循环中输入正确的数字.它现在似乎正在做的是再一次重复循环,要求输入正确,然后显示结束消息.如果满足条件,不确定为什么重复它

String name = JOptionPane.showInputDialog(null,
        "Please enter students lastname");

int input = Integer.parseInt(JOptionPane.showInputDialog(null,
        "Please enter students ID"));

do {
    JOptionPane.showMessageDialog(null,
            "Please enter a student ID within the correct parameters");
    input = Integer.parseInt(JOptionPane.showInputDialog(null,
            "Please enter students ID"));
} while (input < 1 && input > 1000);

// Output dialog with user input
JOptionPane.showMessageDialog(null, "StudentID: " + input
        + "\nStudent Last: " + name);
Run Code Online (Sandbox Code Playgroud)

java do-while

0
推荐指数
1
解决办法
1840
查看次数

标签 统计

do-while ×1

java ×1