新手·小白

输当年截止月共多少天代码

Scanner input = new Scanner(System.in);
		System.out.print("请输入年份:");
		int year =input.nextInt();
		System.out.print("请输入月份:");
		int mouth=input.nextInt();
		int day=0;
		for(int i=1;i<=mouth;i++) {
			switch(i) {
			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;
			}
		}
		System.out.println("该年天数:"+day);

  

posted on 2021-09-20 21:32  新手·小白  阅读(57)  评论(0编辑  收藏  举报

导航