给年份year,定义一个宏,以判别该年份是否闰年。提示:宏名可以定义为LEAP_YEAR,形参为y,既定义宏的形式为 #define LEAP_YEAR(y) (读者设计的字符串)

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int y=scanner.nextInt();
YearTest st1 = new YearTest();//实例化
st1.dataYear(y); //调用方法
}
}
class YearTest {
private int y;
public void dataYear(int y) { //方法
this.y = y;
if((y%4==4)&&(y%100!=0)||(y%400==0)){//判断年份
    System.out.println("L");
}
else 
    System.out.println("N");
}
}

猜你喜欢

转载自blog.csdn.net/qq_39822872/article/details/83450464