网络121第3周实验

来源:互联网 发布:路由器对网络稳定性 编辑:程序博客网 时间:2024/05/16 13:06

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);}}}

运行结果:


0 0
原创粉丝点击