第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么 eclipse 說(shuō)我的方法沒(méi)有返回有效的結(jié)果?

為什么 eclipse 說(shuō)我的方法沒(méi)有返回有效的結(jié)果?

Qyouu 2021-10-27 10:18:44
一段時(shí)間以來(lái),我一直在用 Java 為數(shù)獨(dú)游戲編寫(xiě)此代碼,但我不知道有什么問(wèn)題,也許是“if”或 de“For”,但 IDE 說(shuō)我的方法不返回布爾值類型。// check if the number has already been used in the columnsprivate boolean checkColumns(int x, int y, int value) {    for (int j = 0; j < 9; j++) {        if (this.gridPlayer[j][y].getValue() == value) return false;        else return true;    }    }// Check if the number has already been used in the linesprivate boolean checkLines(int x, int y, int value) {    for (int i = 0; i <= 9; i++) {        if (this.gridPlayer[x][i].getValue() == value) return false;         else return true;    }    }// Check if the number has already been used and the subGridprivate boolean checkSubGrid(int x, int y) {    for (int i = 0; i <= 9; i++) {        for (int j = 0; j <= 9; j++) {            if (this.gridPlayer[x][y].getValueOfSubGrid(x, y) == this.gridPlayer[i][j].getValueOfSubGrid(i, j)) {                if (this.gridPlayer[x][y].getValue() == this.gridPlayer[i][j].getValue()) {                    return false;                } else {                    return true;                }            } else if (this.gridPlayer[x][y].getValueOfSubGrid(x, y) != this.gridPlayer[i][j].getValueOfSubGrid(i,                    j)) {                return true;            }        }    }}
查看完整描述

2 回答

?
GCT1015

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊

歡迎,

在您的checkSubGrid()方法中,如果運(yùn)行時(shí)未在最后一個(gè)輸入,您需要返回一個(gè)值else if: else if (this.gridPlayer[x][y]...) {


如果方法不是void,則需要返回。


 if(a > 1) {

   return a;

 } else {

   return b;

 }

在上面的這種情況下,我們有一個(gè)if - else語(yǔ)句,該方法將始終返回 true 或 false(或有異常)。


 if(a > 1) {

   return a;

 } else if(a == 0) {

   return b;

 }

另一方面,該方法可以或不能進(jìn)入第二個(gè)if,他們沒(méi)有回報(bào)。您不能確保編譯器會(huì)返回。


您可以通過(guò)放置默認(rèn)返回或放置 else 語(yǔ)句來(lái)解決此問(wèn)題。


 if(a > 1) {

   return a;

 } else if(a == 0) {

   return b;

 } else {

   return null;

 }

或者


 if(a > 1) {

   return a;

 } else if(a == 0) {

   return b;

 }

 return null;


查看完整回答
反對(duì) 回復(fù) 2021-10-27
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

編譯器假設(shè)它不是 100% 確定將調(diào)用“for”循環(huán)中的 return 語(yǔ)句,因此它看到的路徑是您的方法不返回任何值,即使它們聲明它們返回。


您需要在循環(huán)之外有一些返回值,即使您確定這永遠(yuǎn)不會(huì)發(fā)生,即


private boolean checkLines(int x, int y, int value) {

  for (int i = 0; i <= 9; i++) {

    if (this.gridPlayer[x][i].getValue() == value) return false;

     else return true;

  }

 return false; //even if you think it will never be run it is necessary 

}


查看完整回答
反對(duì) 回復(fù) 2021-10-27
  • 2 回答
  • 0 關(guān)注
  • 186 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)