gpt4 book ai didi

input - 如何限制输入整数从 1 到 9

转载 作者:行者123 更新时间:2023-12-02 04:53:12 25 4
gpt4 key购买 nike

我有一个用于点球大战游戏的 Java 程序,我想将 b1、b2、b3 和 s1 限制为 1-9 中的任意数字。如果输入不等于 1-9 再试一次。

 for (int i=0;i<=5;i++)

{

int b1, b2, b3, s1;
int j=i+1;
System.out.println("Enter the Numbers which you will block.... Please remember that it should be from 1-9 and nothingelse, 1 2 3 4 5 6 7 8 9");


b1=Integer.parseInt(br.readLine()); // how to restrict this to numbers between 1 to 9
b2=Integer.parseInt(br.readLine()); //this also
b3=Integer.parseInt(br.readLine()); //this also

System.out.flush();
System.out.println("Enter The Number where you will score");
s1=Integer.parseInt(br.readLine()); //this also

最佳答案

while(b1 > 9 || b1 < 1) {
System.out.println("Wrong number. Try again.");
b1=Integer.parseInt(br.readLine());
}

关于input - 如何限制输入整数从 1 到 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25820229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com