Ⅰ 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);
}