编程实现从键盘上输入年份和月份,即可输出该页对应的天数含(闰年)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编程实现从键盘上输入年份和月份,即可输出该页对应的天数含(闰年)相关的知识,希望对你有一定的参考价值。
c语言实现如下:#include<stdio.h>
void main()
int year,month;
int day[12]=31,28,31,30,31,30,31,31,30,31,30,31;
printf("请输入年份与月份:\n");
scanf("%d%d",&year,&month);
if (year%4==0&&year%100!=0||year%400==0) day[1]++;
//判断是否为闰年,是则给原2月天数加一天。
printf("%d年%d月有%d天\n",year,month,day[month-1]);
参考技术A import java.util.Scanner;
public class Test
public static void main(String[] args)
Scanner scan = new Scanner(System.in);
System.out.print("请出入年份:");
int year = scan.nextInt();
System.out.println("请出入月份:");
int month = scan.nextInt();
int datOfMonth = 0;
switch (month)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
datOfMonth = 31;
break;
case 2:
if (isRunNian(year))
datOfMonth = 29;
else
datOfMonth = 28;
break;
default:
datOfMonth = 30;
break;
System.out.println(year + "年的" + month + "月共有" + datOfMonth + "天");
// 判断是否是闰年
public static boolean isRunNian (int year)
boolean flag = false;
if (year/4 == 0
|| (year/100 == 0 && year/400 != 0))
flag = true;
return flag;
本回答被提问者采纳
python输入年份月份输出天数_输入年份月份输出对应的天数
方法1.
//数据输入
Scanner scanner=new Scanner(System.in);
System.out.println("请输入年份(例如2012)");
int year=scanner.nextInt();
System.out.println("请输入月份");
int mounth=scanner.nextInt();
scanner.close();
//判断是不是闰年
boolean isrui=(year%4==0&&year%100!=0) || year%400==0;
//判断月份
if(isrui)
switch(mounth)
case 1:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 2:
System.out.println(year+"年"+mounth+"月有"+29+"天");
break;
case 3:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 4:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 5:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 6:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 7:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 8:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 9:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 10:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 11:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 12:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
else
switch(mounth)
case 1:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 2:
System.out.println(year+"年"+mounth+"月有"+28+"天");
break;
case 3:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 4:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 5:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 6:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 7:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 8:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 9:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 10:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
case 11:
System.out.println(year+"年"+mounth+"月有"+30+"天");
break;
case 12:
System.out.println(year+"年"+mounth+"月有"+31+"天");
break;
方法二.
Scanner s=new Scanner(System.in);
System.out.println("请输入年份----");
int a=s.nextInt();
System.out.println("请输入月份----");
int b=s.nextInt();
int day=0;
//可以输入,但是未完!!!
switch(b)
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((a%4==0&&(a%100!=0||(a%400==0))))
day=29;
else
day=28;
break;
System.out.println(a + "年" + b + "月份 " + "有" + day + "天");
以上是关于编程实现从键盘上输入年份和月份,即可输出该页对应的天数含(闰年)的主要内容,如果未能解决你的问题,请参考以下文章