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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

請(qǐng)問(wèn)下面的代碼,為什么不會(huì)提示id重復(fù)?跪求解答

public void createPlayer() ?{

System.out.println("------------------創(chuàng)建玩家---------------------");

Integer id;

String name;

int i=0;

for(int j=0;j<2;j++) {

while(true) {

try{

System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)玩家的id:");

id=dllx.nextInt();

if(player.contains(new Players(id,null))){

System.out.println("你輸入的id已被使用!請(qǐng)重新輸入!");

continue;

}

break;

} catch (Exception ?e) {

System.out.println("你的輸入有誤,請(qǐng)重新輸入!");

dllx=new Scanner(System.in);

continue;

}

}

while(true){

System.out.println("請(qǐng)輸入第"+(i+1)+"個(gè)玩家的姓名:");

name =dllx.next();

if(player.contains(new Players(id,name))) {

System.out.println("你輸入的名字已被使用!請(qǐng)重新輸入!");

continue;

}

break;

}

player.add( new Players(id,name));

i++;

}

}


正在回答

2 回答

簡(jiǎn)單看了一下,還沒(méi)調(diào)試,在分別判斷名字或者id的時(shí)候,比較一個(gè)對(duì)象就可以了, 你方法中好像是傳入了2個(gè)對(duì)象。。。

if(player.contains(new Players(id,null))){

System.out.println("你輸入的id已被使用!請(qǐng)重新輸入!");

continue;

你仔細(xì)梳理下這個(gè)邏輯。。。

0 回復(fù) 有任何疑惑可以回復(fù)我~

你說(shuō)不會(huì)提示用戶名相同的話,那就是 contains()方法有問(wèn)題吧。 你仔細(xì)調(diào)試下。。。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

請(qǐng)問(wèn)下面的代碼,為什么不會(huì)提示id重復(fù)?跪求解答

我要回答 關(guān)注問(wèn)題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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