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

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師寫的程序有bug,如果輸入33-35周,程序就會報索引越界錯誤,因為for循環(huán)里面輸出的是4個值,而最后一周只有33-35這三個值,我研究了很久根據(jù)評論區(qū)的兄弟們指導寫出了自己的代碼,請指教!

public?static?void?main(String[]?args)?{
????String[]?contentList?=?new?String[35];//創(chuàng)建一個長度為35的數(shù)組
????//給數(shù)組中的每個元素賦值
????contentList[0]?=?"【第1周】環(huán)境搭建與語法入門";
????contentList[1]?=?"【第2周】Java語法之循環(huán)、數(shù)組與方法";
????contentList[2]?=?"【第3周】面向對象之封裝與繼承";
????contentList[3]?=?"【第4周】面向對象之單例模式與多態(tài)";
????contentList[4]?=?"【第5周】常用工具類(上)";
????contentList[5]?=?"【第6周】常用工具類(下)";
????contentList[6]?=?"【第7周】常用工具類(下)";
????contentList[7]?=?"【第8周】前端基礎之HTML與CSS";
????contentList[8]?=?"【第9周】前端基礎之JavaScript與綜合案例";
????contentList[9]?=?"【第10周】Java?Web基礎";
????contentList[10]?=?"【第11周】Java?Web基礎";
????contentList[11]?=?"【第12周】常用功能與過濾器";
????contentList[12]?=?"【第13周】監(jiān)聽器與項目實戰(zhàn)";
????contentList[13]?=?"【第14周】監(jiān)聽器與項目實戰(zhàn)";
????contentList[14]?=?"【第15周】MySQL基礎";
????contentList[15]?=?"【第16周】MySQL基礎";
????contentList[16]?=?"【第17周】Java數(shù)據(jù)庫開發(fā)基礎";
????contentList[17]?=?"【第18周】框架前置知識";
????contentList[18]?=?"【第19周】MyBatis基礎";
????contentList[19]?=?"【第20周】MyBatis實現(xiàn)OA系統(tǒng)項目實戰(zhàn)";
????contentList[20]?=?"【第21周】MyBatis實現(xiàn)OA系統(tǒng)項目實戰(zhàn)";
????contentList[21]?=?"【第22周】Linux環(huán)境搭建與Redis應用";
????contentList[22]?=?"【第23周】Spring基礎";
????contentList[23]?=?"【第24周】Spring基礎";
????contentList[24]?=?"【第25周】Spring基礎";
????contentList[25]?=?"【第26周】SSM開發(fā)社交網(wǎng)站";
????contentList[26]?=?"【第27周】Spring?Boot電商項目實戰(zhàn)";
????contentList[27]?=?"【第28周】Spring?Boot電商項目實戰(zhàn)";
????contentList[28]?=?"【第29周】面試";
????contentList[29]?=?"【第30周】多線程與分布式";
????contentList[30]?=?"【第31周】多線程與分布式";
????contentList[31]?=?"【第32周】Spring?Cloud基礎";
????contentList[32]?=?"【第33周】Spring?Cloud電商實戰(zhàn)";
????contentList[33]?=?"【第34周】Spring?Cloud電商實戰(zhàn)";
????contentList[34]?=?"【第35周】Zookeeper+Dubbo應用與面試";
????//提示信息
????System.out.print("您要開始第幾周學習啦,直接輸入數(shù)字吧:");
????int?w?=?new?Scanner(System.in).nextInt();
????if(w?>?0?&&?w?<=?contentList.length)?{//控制w的取值范圍
????????//計算今天是幾月(1-月第一周;4-月第四周)
????????int?month?=?0;
????????if?(w?%?4?==?0)?{
????????????month?=?w?/?4;
????????}?else?{
????????????month?=?w?/?4?+?1;
????????}
????????//提示信息
????????System.out.println("以下是您本月的學習計劃,√代表當前學習任務");
????????System.out.println("==================================");
????????//利用for循環(huán),找到數(shù)組中對應這個月的內容輸出
????????for?(int?i?=?(month?-?1)?*?4;?i?<?month?*?4?&&?i?<?contentList.length;?i++)?{
????????????if?(i?==?(w?-?1))?{
????????????????System.out.println("√"?+?contentList[i]);
????????????}?else?{
????????????????System.out.println(contentList[i]);
????????????}
????????}
????}else?{//如果輸入的w值不在if范圍內,則輸出:
????????System.out.println("當前周沒有課程!");
????}

????}
}


正在回答

3 回答

最后寫了try catch捕獲了異常

0 回復 有任何疑惑可以回復我~
//利用for循環(huán),找到數(shù)組中對應這個月的內容輸出(考慮*4是否大于數(shù)組本身長度)
for(int?i?=?(mouth?-1?)?*?4;i<?(mouth?*?4<contentList.length???mouth?*?4?:?contentList.length);i++)?{
????if(i?==?(num-1))
????{
????????System.out.println("√"+contentList[i]);
????}
????else
????{
????????System.out.println(contentList[i]);
????}
}


0 回復 有任何疑惑可以回復我~

你把當前這個月的信息拉到數(shù)組一個長度為4的數(shù)組里,第35周就是第9周,多的36周為空就可以了

http://img1.sycdn.imooc.com//611a21b90001e7cd07160737.jpg

0 回復 有任何疑惑可以回復我~
#1

W2796003 提問者

受教了,謝謝!
2021-08-16 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

老師寫的程序有bug,如果輸入33-35周,程序就會報索引越界錯誤,因為for循環(huán)里面輸出的是4個值,而最后一周只有33-35這三個值,我研究了很久根據(jù)評論區(qū)的兄弟們指導寫出了自己的代碼,請指教!

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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