你好,按照你的要求代碼如下,給出了注釋?zhuān)梢灾苯舆\(yùn)行
創(chuàng)新互聯(lián)公司主營(yíng)懷仁網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,手機(jī)APP定制開(kāi)發(fā),懷仁h5微信小程序搭建,懷仁網(wǎng)站營(yíng)銷(xiāo)推廣歡迎懷仁等地區(qū)企業(yè)咨詢(xún)
public class Example10_3 {
public static void main(String args[]) {
// 從1月打到12月
for (int i = 1; i = 12; i++) {
System.out.println(getSeason(i));
}
}
// 根據(jù)月份獲得季節(jié)
private static String getSeason(int month) {
switch ((month - 1) / 3) {
case 0:
return "春";
case 1:
return "夏";
case 2:
return "秋";
case 3:
return "冬";
default:
return "錯(cuò)誤";
}
}
}
話(huà)不多說(shuō),直接上代碼。
Scanner sc = new Scanner(System.in);
System.out.print("請(qǐng)輸入月份 : ");
String monthStr = sc.next();
int month = Integer.parseInt(monthStr);
if (month = 3 month = 5) {
System.out.println("春季");
} else if (month = 6 month = 8) {
System.out.println("夏季");
} else if (month = 9 month = 11) {
System.out.println("秋季");
} else if (month == 12 || month = 2) {
System.out.println("冬季");
} else {
System.out.println("沒(méi)有該月份 " + month);
}
代碼喝注釋如下:
public?static?void?main(String[]?args)?{??System.out.print("Please?input?the?month?to?check:");??int?month?=?new?Scanner(System.in).nextInt();//月份//月份不在1~12的情況,提醒輸入錯(cuò)誤??if?(month?=?0?||?month??12)?{???System.out.println("Error!?month?must?be?between?1?and?12!");??}?
//1-3月是春天
else?if?(month?=?3)?{???System.out.println("Month?"?+?month?+?"?is?in?Spring!");??}?
//4-6月是夏天
else?if?(month?=?6)?{???System.out.println("Month?"?+?month?+?"?is?in?Summer!");??}?
//7-9月是秋天
else?if?(month?=?9)?{???System.out.println("Month?"?+?month?+?"?is?in?Autumn!");??}?
//10-12月是冬天
else?{???System.out.println("Month?"?+?month?+?"?is?in?Winter!");??}?}
標(biāo)題名稱(chēng):java四季代碼 javagui代碼
本文地址:http://chinadenli.net/article10/dogdggo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、軟件開(kāi)發(fā)、App設(shè)計(jì)、網(wǎng)站策劃、靜態(tài)網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
全網(wǎng)營(yíng)銷(xiāo)推廣知識(shí)