欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

打印某年某月多少天

程序员文章站 2022-10-03 14:48:32
package day1;import java.util.Scanner;public class Test1{public static void main(String[] args) {Scanner scanner = new Scanner(System.in); System.out.println(“请输入年份”);int year = scanner.nextInt(); System.out.println(“请输入月份”);int...

package day1;
import java.util.Scanner;
public class Test1{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); System.out.println(“请输入年份”);
int year = scanner.nextInt(); System.out.println(“请输入月份”);
int month = scanner.nextInt();
if (year % 4 == 0 || year % 400 == 0) { System.out.println(year + “年” + “是闰年366天”); } else if (year % 100 != 0) { System.out.println(year + “年” + “是平年365天”); } switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
System.out.println(year + “年” + month + “月是31天”);
break;
case 2:

if (year % 4 == 0 || year % 400 == 0) {			System.out.println(year + "年" + month + "月是29天");			} else if (year % 100 != 0) {				
System.out.println(year + "年" + month + "月是28天");			}			
break;		
case 4:		
case 6:		
case 9:		
case 11:			
System.out.println(year + "年" + month + "月是30天");			break;		
default:			
System.out.println("请重新输入");

本文地址:https://blog.csdn.net/qq_50966209/article/details/109274349

相关标签: 笔记