close

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

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Icen Zhong 的頭像
    Icen Zhong

    無止盡的Coding地獄

    Icen Zhong 發表在 痞客邦 留言(0) 人氣()