導航:首頁 > 編程語言 > java重構ifelse

java重構ifelse

發布時間:2025-10-11 22:20:15

1. java萬年歷總是日期不對,求教!!

import java.util.Scanner;

public class bxm {

/**
* @param args
*/
@SuppressWarnings("resource")
public static void main(String[] args) {
// TODO Auto-generated method stub
int i;
int year;
int month;
int dw;
int monthday = 0;
int ww=2;
int totalday=0;
System.out.println("*********歡迎使用萬年歷×××××××××");
System.out.println("\n請輸入年份");
Scanner input = new Scanner(System.in);
year = input.nextInt();
System.out.println("\n請輸入月份");
Scanner input1 = new Scanner(System.in);
month = input1.nextInt();
switch(month)
{ case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: monthday=31;break;
case 4:
case 6:
case 9:
case 11: monthday=30;break;
case 2:
if (year%4==0&&year%100!=0||year%400==0)//100是!=
monthday=29;
else
monthday=28;
break;
default:break;
}
for(i=1980;i<year;i++)
{
totalday+=365;
}
for(i=1980;i<year;i++)
{if (i%4==0&&i%100!=0||i%400==0)//100是!=,同時使用的是i不是year
totalday++;
}
for(i=1;i<month;i++)//《=去掉=
{switch(i)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: totalday+=31;break;
case 4:
case 6:
case 9:
case 11: totalday+=30;break;
case 2:
if (year%4==0&&year%100!=0||year%400==0)////100是!=
totalday+=29;
else
totalday+=28;
break;
}
}
dw=(ww+totalday)%7;
System.out.println("列印這個月月歷如下");
System.out.println(" 日 一 二 三 四 五 六 ");
for(i=1;i<=dw;i++)
{
System.out.print(" ");
}
for(i=1;i<=monthday;i++)
{
System.out.print(" "+i);
if((i+dw)%7==0)
System.out.println("");
}
}
}

//好像就改了這些,再有不同你自己找吧

閱讀全文

與java重構ifelse相關的資料

熱點內容
java獲取窗口游標的位置 瀏覽:593
掃描配置文件內容組合成變數 瀏覽:889
精雕編程培訓龍區中心城附近哪裡有 瀏覽:181
中興測試代碼 瀏覽:288
u盤中毒文件夾打不開 瀏覽:984
遍歷文件夾獲取文件名稱 瀏覽:768
為什麼想成為程序員 瀏覽:973
程序設計大賽例題 瀏覽:38
excel表格數據怎麼輸出多個文件夾 瀏覽:259
怎麼用wps製作多張照片pdf文件 瀏覽:439
什麼時候有中文編程 瀏覽:141
軟體里的文件怎麼刪掉 瀏覽:58
js小數類型字元串變成整數 瀏覽:832
電腦密碼保存在那個文件里 瀏覽:279
每次打開cad文件都會打開一個網頁 瀏覽:206
金華ps怎麼自己製作網站 瀏覽:43
微信彤彤去疤 瀏覽:806
appstoreapp轉讓流程 瀏覽:913
java重構ifelse 瀏覽:136
ps打開文件總是合並到一個窗 瀏覽:143

友情鏈接