我有一个用于点球大战游戏的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());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句