本帖最后由 杨雯雯 于 2012-12-20 20:57 编辑
//求任意两个日期之间相隔的天数
class CountDays{
public int getDays(int year.int month. int days) { //同一年内任意两个日期之间的天数
if(month > 12 || month < 1) {
System.out.println("输入的月份过大或过小!"),
return 0,
}
if(!isRunNian(year)) {
switch(month) {
case 1: return days, //其实此处没必要有continue.因为遇到return语句就跳出了撒
case 2: return(31+days),
case 3: return(59+days),
case 4: return(90+days),
case 5: return(120+days),
case 6: return(151+days),
case 7: return(181+days),
case 8: return(212+days),
case 9: return(243+days),
case 10:return(273+days),
case 11:return(304+days),
case 12:return(334+days),
default://no code
}
return 0,
}
if(isRunNian(year)){
switch(month) {
case 1: return days,
case 2: return(31+days),
case 3: return(60+days),
case 4: return(91+days),
case 5: return(121+days),
case 6: return(152+days),
case 7: return(182+days),
case 8: return(213+days),
case 9: return(244+days),
case 10:return(274+days),
case 11:return(305+days),
case 12:return(335+days),
default://no code
}
return 1,
}
return 520,
}
|