import java.util.*;
public class Demo25
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份:");
int year = scan.nextInt();//2014
System.out.println("请输入一个月份:");
int month = scan.nextInt();//8
int day = 0;//表示每个月 的天数
int sum = 0;//天数的和。。sum+=31+=28+=相应的天数
for(int i = 1;i<month;i++){
//step1:判断i月份的天数,赋值给day
switch( i ){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 2:
if((year % 4 ==0 &&year % 100 !=0)||(year % 400 == 0)){
day = 29;
}else{
day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
default:
System.out.println("输入的月份有误。。");
}
//step2:在sum上累加day
sum += day;//31
}
System.out.println(month+"月份天数总和:\t"+sum);
}
}
import java.util.*;
public class Demo25
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("请输入一个年份:");
int year = scan.nextInt();//2014
System.out.println("请输入一个月份:");
int month = scan.nextInt();//8
int day = 0;//表示每个月 的天数
int sum = 0;//天数的和。。sum+=31+=28+=相应的天数
for(int i = 1;i<month;i++){
//step1:判断i月份的天数,赋值给day
switch( i ){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day = 31;
break;
case 2:
if((year % 4 ==0 &&year % 100 !=0)||(year % 400 == 0)){
day = 29;
}else{
day = 28;
}
break;
case 4:
case 6:
case 9:
case 11:
day = 30;
break;
default:
System.out.println("输入的月份有误。。");
}
//step2:在sum上累加day
sum += day;//31
}
System.out.println(month+"月份天数总和:\t"+sum);
}
}