一个小程序,求帮助
编写一个程序,要求随意输入一个日期如:2007,1,1得到该日期是星期几,并输出
public class webDate { public static void main(String[] args) { date("2013.3.28"); } public static void date(String date) { //天数 int tmpSumDay = 0 ; //星期 String weekS = ""; String[] findDate = date.split("\\."); int[] userDate = new int[3]; //转换string->int for(int i = 0 ; i < findDate.length ; ++i) { userDate[i] = Integer.parseInt(findDate[i]); } //计算年 for(int year = 1900 ; year < userDate[0] ; ++year) { if(year % 4 == 0 && year % 100 != 0 || year % 400 ==0) { tmpSumDay += 366; } else { tmpSumDay += 365; } } //计算月 for(int tMonth = 1 ; tMonth < userDate[1] ; ++ tMonth) { if(tMonth == 2) { if(userDate[0] % 4 == 0 && userDate[0] % 100 != 0 || userDate[0] % 400 == 0) { tmpSumDay+= 29; } else { tmpSumDay+= 28; } } else if(tMonth == 4 || tMonth == 6 ||tMonth == 9 ||tMonth == 11) { tmpSumDay+= 30; } else { tmpSumDay+= 31; } } //计算天 tmpSumDay += userDate[2]; //判断 int week = tmpSumDay % 7; switch(week) { case 1: weekS = "星期一"; break; case 2: weekS = "星期二"; break; case 3: weekS = "星期三"; break; case 4: weekS = "星期四"; break; case 5: weekS = "星期五"; break; case 6: weekS = "星期六"; break; case 7: weekS = "星期日"; break; } System.out.println(weekS); } }