java - 我的井字游戏方法之一出错

标签 java

我不断收到以下错误。

用户只能输入 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/

相关文章:

java - 应用程序中的 Hibernate .hbm.xml 文件路径?

java - 将 "Unchecked cast from Object to Map<String,Object>"包装在 try/catch(ClassCastException) 中是否足以避免运行时问题?

java - ListView 随时间更新

java - 是否可以使用 Java Guava 将函数应用于集合?

java - 如何使用 netbeans 在 Java 中直接从 GUI 更新访问数据库表

java - 当选择复选框时,Appium 中的另一个元素文本会发生变化

java - 简单的Java并发线程——捕获开始和结束

java - 为什么不能将 RandomAccessFile 转换为 Inputstream?

java - 如何设计新图形以添加到 JFrame 表单中?

java - 运行 java 的预定义输入脚本