課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級版
代碼答案是什么
2021-03-10
源自:Java入門第一季(IDEA工具)升級版 7-1
正在回答
/*什么都不說了,我這個最簡單, ??但是有漏洞,就是沒有做超出35周的糾正 ??但是題目也沒要求這個*/ import?java.util.Scanner; public?class?HelloWorld?{ ????public?static?void?main(String[]?args)?{ ????????//創(chuàng)建String數(shù)組,并為每一個元素賦值。賦值內容為第幾周+學習內容 ????????String[]?contentList?=?new?String[35]; ????????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ù)字吧:"); ????????//設置變量存儲接收到的數(shù)據(jù) ????????int?weeks??=?new?Scanner(System.in).nextInt(); ????????//計算今天是幾月(1-月第一周、4-月第4周) ????????int?month=(weeks-1)/4+1; ???????? ????????//計算輸入的周是這個月的第幾周 ????????int?week=(weeks-1)%4+1; ???????? ????????//提示信息 ????????System.out.println("以下是您本月的學習計劃,?√?代表當周學習任務"); ????????System.out.println("======================================="); ???????? ????????//利用for循環(huán),找到數(shù)組中對應這個月的內容輸出 ????????for(int?i=0;i<4;i++){ ????????????//根據(jù)當前月第幾周,在輸出此行時,前面添加“√” ????????????if(i==week-1){ ????????????????System.out.print("√"); ????????????} ????????????System.out.println(contentList[4*(month-1)+i]); ????????}???? ????} }
數(shù)組長度為35,然后你在for循環(huán)內下i = day-1。? 那么i不可能到35啊,你在for內部賦值,又把i作為循環(huán)遞增數(shù)。所以就會一直循環(huán)(死循環(huán)),跳不出來。
import java.util.Scanner;
public class HelloWorld{
? ? public static void main(String[] args) {
? ? ? ? //創(chuàng)建String數(shù)組,并為每一個元素賦值。賦值內容為第幾周+學習內容
? ? ? ? String[] contentList = new String[35];
? ? ? ? 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ù)字吧:");
? ? ? ? //設置變量存儲接收到的數(shù)據(jù)
? ? ? ? int? days? = new Scanner(System.in).nextInt();
? ? ? ? //計算今天是幾月(1-月第一周、4-月第4周)
? ? ? ? int month;
? ? ? ? if(days%4==0)
? ? ? ? month = (int)days/4;
? ? ? ? else
? ? ? ? ? ? month = days/4 +1;
? ? ? ? System.out.println("月份:"+month);
? ? ? ? System.out.println("以下是您本月的學習計劃, √ 代表當周學習任務");
? ? ? ? System.out.println("=======================================");
? ? ? ? //利用for循環(huán),找到數(shù)組中對應這個月的內容輸出
? ? ? ? if (days<=32) {
? ? ? ? ? ? for (int i = month * 4 - 4; i < month * 4; i++)
? ? ? ? ? ? ? ? System.out.println(contentList[i]);
? ? ? ? ? ? //根據(jù)當前月第幾周,在輸出此行時,前面添加“√”
? ? ? ? ? ? for (int i = days - 1; i < month * 4; i++)
? ? ? ? ? ? ? ? System.out.println("√" + contentList[i]);
? ? ? ? }
? ? ? ? else if(days>32){
? ? ? ? ? ? for (int i = month * 4 - 4; i <=34; i++)
? ? ? ? ? ? for (int i = days - 1; i < month * 4; i++) {
? ? ? ? ? ? ? ? if (i==34)
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? }
出現(xiàn)這種情況要么是死循環(huán),要么全部輸出一條語句
?for( i=0;i<=contentList.length;i++){
? ? ? ? if(day>0&&day<=35){
? ? ? ? i=day-1;
這個地方你在for中已經給 i 給了一個遞增的條件,下面又給???i=day-1;? ?就存在錯誤。
package experience03_11;
public class Demo08 {
? ? ? ? int day? = new Scanner(System.in).nextInt();
? ? ? ? int month=(int)(day/4+1);
? ? ? ? if(day%4==0)
? ? ? ? {month--;}
? ? ? ? System.out.println("這周屬于是"+month+"月");
? ? ? ? //計算輸入的周是這個月的第幾周
? ? ? ? int week;
? ? ? ? if(day%4==0){
? ? ? ? week=4;
? ? ? ? }else{
? ? ? ? week=(int)(day%4);
? ? ? ? System.out.println("這周是第"+week+"周");
? ? ? ? int i;
? ? ? ? for( i=0;i<=contentList.length;i++){
? ? ? ? System.out.println("√"+contentList[i]);
? ? ? ? }else
? ? ? ? {
? ? ? ? System.out.println("您輸入的數(shù)據(jù)有誤!");
? ? //根據(jù)當前月第幾周,在輸出此行時,前面添加“√”? ? ? ?
}
有沒有大神可以幫忙看一下啊,我的代碼一直不斷輸出,類似下圖
舉報
0基礎萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎語法開始
3 回答答案是什么
2 回答為什么答案是30
1 回答答案答案答案
3 回答為什么A答案是錯的,求解答
1 回答代碼和答案一樣 但報錯
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2022-09-08
2021-05-17
數(shù)組長度為35,然后你在for循環(huán)內下i = day-1。? 那么i不可能到35啊,你在for內部賦值,又把i作為循環(huán)遞增數(shù)。所以就會一直循環(huán)(死循環(huán)),跳不出來。
2021-05-17
import java.util.Scanner;
public class HelloWorld{
? ? public static void main(String[] args) {
? ? ? ? //創(chuàng)建String數(shù)組,并為每一個元素賦值。賦值內容為第幾周+學習內容
? ? ? ? String[] contentList = new String[35];
? ? ? ? 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ù)字吧:");
? ? ? ? //設置變量存儲接收到的數(shù)據(jù)
? ? ? ? int? days? = new Scanner(System.in).nextInt();
? ? ? ? //計算今天是幾月(1-月第一周、4-月第4周)
? ? ? ? int month;
? ? ? ? if(days%4==0)
? ? ? ? month = (int)days/4;
? ? ? ? else
? ? ? ? ? ? month = days/4 +1;
? ? ? ? //提示信息
? ? ? ? System.out.println("月份:"+month);
? ? ? ? System.out.println("以下是您本月的學習計劃, √ 代表當周學習任務");
? ? ? ? System.out.println("=======================================");
? ? ? ? //利用for循環(huán),找到數(shù)組中對應這個月的內容輸出
? ? ? ? if (days<=32) {
? ? ? ? ? ? for (int i = month * 4 - 4; i < month * 4; i++)
? ? ? ? ? ? ? ? System.out.println(contentList[i]);
? ? ? ? ? ? //根據(jù)當前月第幾周,在輸出此行時,前面添加“√”
? ? ? ? ? ? for (int i = days - 1; i < month * 4; i++)
? ? ? ? ? ? ? ? System.out.println("√" + contentList[i]);
? ? ? ? }
? ? ? ? else if(days>32){
? ? ? ? ? ? for (int i = month * 4 - 4; i <=34; i++)
? ? ? ? ? ? ? ? System.out.println(contentList[i]);
? ? ? ? ? ? //根據(jù)當前月第幾周,在輸出此行時,前面添加“√”
? ? ? ? ? ? for (int i = days - 1; i < month * 4; i++) {
? ? ? ? ? ? ? ? System.out.println("√" + contentList[i]);
? ? ? ? ? ? ? ? if (i==34)
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
2021-03-16
出現(xiàn)這種情況要么是死循環(huán),要么全部輸出一條語句
?for( i=0;i<=contentList.length;i++){
? ? ? ? if(day>0&&day<=35){
? ? ? ? i=day-1;
這個地方你在for中已經給 i 給了一個遞增的條件,下面又給???i=day-1;? ?就存在錯誤。
2021-03-14
package experience03_11;
import java.util.Scanner;
public class Demo08 {
? ? public static void main(String[] args) {
? ? ? ? //創(chuàng)建String數(shù)組,并為每一個元素賦值。賦值內容為第幾周+學習內容
? ? ? ? String[] contentList = new String[35];
? ? ? ? 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ù)字吧:");
? ? ? ? //設置變量存儲接收到的數(shù)據(jù)
? ? ? ? int day? = new Scanner(System.in).nextInt();
? ? ? ? //計算今天是幾月(1-月第一周、4-月第4周)
? ? ? ? int month=(int)(day/4+1);
? ? ? ? if(day%4==0)
? ? ? ? {month--;}
? ? ? ? System.out.println("這周屬于是"+month+"月");
? ? ? ? //計算輸入的周是這個月的第幾周
? ? ? ? int week;
? ? ? ? if(day%4==0){
? ? ? ? week=4;
? ? ? ? }else{
? ? ? ? week=(int)(day%4);
? ? ? ? }
? ? ? ? System.out.println("這周是第"+week+"周");
? ? ? ? //提示信息
? ? ? ? System.out.println("以下是您本月的學習計劃, √ 代表當周學習任務");
? ? ? ? System.out.println("=======================================");
? ? ? ? int i;
? ? ? ? //利用for循環(huán),找到數(shù)組中對應這個月的內容輸出
? ? ? ? for( i=0;i<=contentList.length;i++){
? ? ? ? if(day>0&&day<=35){
? ? ? ? i=day-1;
? ? ? ? System.out.println("√"+contentList[i]);
? ? ? ? }else
? ? ? ? {
? ? ? ? System.out.println("您輸入的數(shù)據(jù)有誤!");
? ? ? ? }
? ? ? ? }
? ? //根據(jù)當前月第幾周,在輸出此行時,前面添加“√”? ? ? ?
? ? }
}
有沒有大神可以幫忙看一下啊,我的代碼一直不斷輸出,類似下圖