import java.util.*;
public class leapyear
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int year;
System.out.printf("請輸入年分(西元): ");
year = sc.nextInt();
if (year <= 0)//判斷輸入年分若為負數則印出提示並結束
{
System.out.printf("就說西元了你還輸入負的!!");
}
else if( ( year % 4 == 0) && ( year % 100 != 0 ) )//判斷輸入年分是否被4整除並無法被100整除
{
System.out.printf("西元%d年為閏年!",year);
}
else if( ( year % 400 == 0 ) && ( year % 4000 != 0 ))//判斷是否能被400整除並無法被4000整除
{
System.out.printf("西元%d年為閏年!",year);
}
else
{
System.out.printf("西元%d年不為閏年!",year);
}
}
}
- Mar 22 Tue 2011 01:55
110321物件作業--(2)閏年
close
全站熱搜
留言列表
發表留言