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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

一個java入門編程小問題?

一個java入門編程小問題?

明月笑刀無情 2019-04-08 11:17:08
publicclassCount3Quit{publicstaticvoidmain(String[]args){boolean[]arr;arr=newboolean[500];for(inti=0;i1){if(arr[index]=true){now=now+1;if(now==3){arr[index]=false;left=left-1;now=0;}}index=index+1;if(index==arr.length){index=0;}}for(inti=0;i
查看完整描述

2 回答

?
慕俠2389804

TA貢獻1719條經(jīng)驗 獲得超6個贊

你犯了一個基本的錯誤
if(arr[index]=true){
這里應(yīng)該是==
沒有試你的程序,不知道還有沒有別的問題
                            
查看完整回答
反對 回復(fù) 2019-04-08
?
月關(guān)寶盒

TA貢獻1772條經(jīng)驗 獲得超5個贊

對應(yīng)的問題,有對應(yīng)的數(shù)據(jù)結(jié)構(gòu),這個題目出現(xiàn)在很多的招聘面試題目中,是一個經(jīng)典的應(yīng)用循環(huán)鏈表的示例。恰好有時間,寫了一下代碼。廢話不多說,上代碼,有問題,歡迎討論:
publicclassthirdPersonOutGame{
publicstaticvoidmain(String[]args){
pointTheLastPerson(init(3),true);
}
staticPersoninit(inttotalPersonNum){
if(totalPersonNum<=0){
thrownewIllegalArgumentException("totalpersonnumbercannotbezero.");
}
Personhead=newPerson(1);
Personprev=head;
for(inti=2;i<=totalPersonNum;i++){
prev=prev.next(newPerson(i));
}
prev.next(head);
System.out.printf("total%dpersonsjointhegame\n",totalPersonNum);
returnhead;
}
staticvoidpointTheLastPerson(Personhead,booleanwhetherPrintQuitOrder){
Personprev=head;
Personcur=head;
intcurIndex=1;
if(whetherPrintQuitOrder){System.out.print("personoutorder:");}
while(cur.next!=cur){
prev=cur;
cur=cur.next;
if(++curIndex==3){
if(whetherPrintQuitOrder){
System.out.printf("%d",cur.i);
}
cur=curPersonOut(cur,prev);
curIndex=1;
}
}
if(whetherPrintQuitOrder){System.out.println();}
System.out.printf("thelastperson:%d\n",cur.i);
}
staticPersoncurPersonOut(Personcur,Personprev){
returnprev.next=cur.next;
}
staticclassPerson{
inti;
Personnext;
Person(inti){
this.i=i;
}
Personnext(Personperson){
returnthis.next=person;
}
}
}
                            
查看完整回答
反對 回復(fù) 2019-04-08
  • 2 回答
  • 0 關(guān)注
  • 415 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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