Ⅰ java程序一年里一个月有多少天
package Day02;
import java.util.Scanner;
public class YearandMonth {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入年份>");
int year = scan.nextInt();
System.out.println("请输入月份");
int month = scan.nextInt();
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
System.out.println("该月份有31天");
}else if (month == 2){
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
System.out.println("该月份有29天");
}else{
System.out.println("该月份有28天");
}
}else if (month == 4 || month == 6 || month == 9 || month == 11){
System.out.println("该月份有30天");
}else{
System.out.println("没有该月份");
}
}
}
Ⅱ c语言编写程序从键盘输入年份和月份,计算出这一年的这一个月有多少天
#include<stdio.h>
int main()
{
int year,month,days,day;
printf("请输入年月日");
scanf("%d-%d-%d",&year,&month,&days);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31;break;
case 4:
case 6:
case 9:
case 11:day=30;break;
case 2:
if(year%4==0&&year%100!=0||year%400==0)
day=29;
else
day=28;break;
default :printf("error ");
}
printf("这个月有%d天",day);
}