課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級(jí)版
使用switch語句怎么寫
2018-09-26
源自:Java入門第一季(IDEA工具)升級(jí)版 4-6
正在回答
public?static?void?main(String[]?args)?{ ????Scanner?input?=?new?Scanner(System.in); ????Exercises?exe?=?new?Exercises(); ????System.out.print("請(qǐng)輸入要計(jì)算的日期:");?//?2018-09-26 ????int?day?=?exe.getDay(input.next()); ????System.out.println(day); } /** ?*?獲取輸入值所對(duì)應(yīng)該年的第幾天 ?* ?*?@param?date ?*?@return ?*/ public?int?getDay(String?date)?{ ????String[]?ymd?=?date.split("-"); ????int?inputYear?=?Integer.valueOf(ymd[0]); ????int?inputMonth?=?Integer.valueOf(ymd[1]); ????int?inputDay?=?Integer.valueOf(ymd[2]); ????int?day?=?0;?//?天數(shù) ????Exercises?exe?=?new?Exercises(); ????for?(int?i?=?1;?i?<=?(inputMonth?-?1);?i++)?{ ????????day?=?day?+?exe.getMonthLastDay(i,?inputYear); ????} ????return?day?+?inputDay; } /** ?*?獲取每個(gè)月的天數(shù) ?* ?*?@param?month ?*?@param?year ?*?@return ?*/ public?int?getMonthLastDay(int?month,?int?year)?{ ????int?day?=?31; ????switch?(month)?{ ????????case?4: ????????case?6: ????????case?9: ????????case?11: ????????????day?=?30; ????????????break; ????????case?2: ????????????if?(year?%?400?==?0??||?(year?%?4?==?0?&&?year?%?100?!=?0))?{?//?判斷是否是閏年 ????????????????day?=?29; ????????????}?else?{ ????????????????day?=?28; ????????????} ????????????break; ????} ????return?day; }
貓骨_ 提問者
謝,大神
舉報(bào)
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
3 回答計(jì)算1年到2017之間的閏年
1 回答現(xiàn)在19年,這個(gè)教程幾年了?
4 回答計(jì)算的平均年齡為什么不對(duì)呢?
1 回答每個(gè)年齡段的判斷應(yīng)該是>=吧?
4 回答符號(hào)計(jì)算是》=還是《=
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-09-26
2018-09-28
謝,大神