特定の年がうるう年であるかどうかを判断するプログラムをJavaで記述します

ある年がうるう年かどうかを判断するプログラムを作成し
ます。うるう年の判断規則は次のとおりです。
(1)年を4で割り切れても、100で割り切れない場合は、うるう年です。
(2)ある年を400で割り切れる場合は、うるう年でもあります。
(初心者が自分でJavaを学ぶための小さな演習)

import java.util.Scanner;

public class TestDemo{
    
    
	public static void main(String[] args){
    
    
		Scanner sc=new Scanner(System.in);//与键盘建立连接
		System.out.println("请输入年份:");
		int year=sc.nextInt();
		int remainder1=year%4;
		int remainder2=year%100;
		int remainder3=year%400;		
		if((remainder1 ==0 && remainder2 !=0) || remainder3==0){
    
    
			System.out.println(year+"是闰年");
		}else{
    
    
			System.out.println(year+"不是闰年");
		}		
	}
}

結果は次のとおりです。
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/weixin_43462140/article/details/114106008