我不断收到以下错误。
用户只能输入 1 到 9 之间的数字。这就是我的错误显示的内容:
hint: does getemptyspot return valid entered spot even with initial zero entry:
hint: does getemptyspot return valid entered spot even with initial 10 entry.
另外,如果板已满,我的代码应该返回 -1
。如果该位置已被占用,我的代码应返回 "That number is not available. Choose another from the numbered spots"
我的代码如下:
public int getEmptySpot()
{
System.out.print("Choose a number where you want your marker to go");
int spot = in.nextInt();
if(b.isAvailable(spot))
{
return spot;
}
if(spot == 0 || spot > 10)
{
System.out.println("That number is not available. Choose another from the numbered spots");
}
return -1;
}
最佳答案
您可以发布isAvailable()
的详细信息吗?
看起来代码无法到达第二个 if()
子程序。
为什么要使用不同样式的 if()
?
尝试这样:
if(spot >0 && spot <10){
return spot;
}else{
}
关于java - 我的井字游戏方法之一出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20462221/