java 基础入门问题

新手上路,请多包涵

今天刚开始自学java,求问一个简单的问题,这个方法为什么不对,错误信息是
Required: Direction(另外一个类?)
found:int
static Direction tileCodeToOrientation(int tileCode) {

int tileIndex = tileCode % 4;
int boardPosition;
if (tileIndex >= 0 && tileIndex<=2){
  boardPosition = tileIndex + 6;
}
   else if (tileIndex >= 3 && tileIndex<=5){
  boardPosition = tileIndex + 8;
}
   else if (tileIndex >= 6 && tileIndex<=8){
  boardPosition = tileIndex + 10;
}


/*  tiles index board         board position
 col:    3 2 1    row:      col:    3 2 1   row:
         0 1 2   1                  0 1 2     1
         3 4 5   2                  3 4 5     2
         6 7 8   3                  6 7 8     3

*/

return boardPosition;
就是想把第一个board上的数字转换成第二个上面的,再输出
阅读 1.2k
1 个回答

个人观点:

static Direction tileCodeToOrientation(int tileCode)

上述方法定义返回类型为Direction,但方法返回值是int类型

int boardPosition;
return boardPosition;

方法语气返回类型和实际返回类型不匹配,所以报错
希望对你有所帮助,谢谢

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题