1:计算闰年。教材P45 编程题2:判断某一年份是否为闰年。(如果这个年份能被4整除,但不能被100整除;或者,如果这个年份能被4整除,又能被400整除;满足以上两个条件中的一个的年份为闰年)。
本程序参考了课本7-5
源码:
import java.io.*;
public class LeapYear {
public static void main(String[]args)throws IOException{
try{
InputStreamReader r;
BufferedReader year;
r=new InputStreamReader(System.in);
year=new BufferedReader(r);
String s=year.readLine();
int i=Integer.parseInt(s);
System.out.println("输入的年份是: "+s);
if(( i% 4 == 0 ) && ( i % 100 != 0 ) || ( i % 400 == 0 ))
System.out.print( s+"是闰年");
else
System.out.print( s+"不是闰年");
}catch (IOException e){
System.out.println(e);
}
}
}
运行结果: