今天剛開始自學java,求問一個簡單的問題,這個方法為什么不對,錯誤信息是Required: Direction(另外一個類?)found:intstatic 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 回答

Cats萌萌
TA貢獻1805條經驗 獲得超9個贊
個人觀點:
static Direction tileCodeToOrientation(int tileCode)
上述方法定義返回類型為Direction,但方法返回值是int類型
int boardPosition;return boardPosition;
方法語氣返回類型和實際返回類型不匹配,所以報錯
希望對你有所幫助,謝謝
添加回答
舉報
0/150
提交
取消