自我介紹
connielee

臺北市立陽明高中
資訊科技概論教師

search
calendar
« 五月 2007 »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
近期文章
文章分類
網站連結
文章彙整
Syndicate
Credits
LifeType IE7 XHTML CSS Firefox

【JAVA程式設計】閏年判斷

2007-05-02 @ 04:49 in 95-112班

/* * 2005/4/22 Connie Lee建立 * 閏年計算規則:「被4整除,且不被100整除,但又能被400整除者」。 * */ 

public class Nestedif {

 

        public static void main(String[] args)

        {

                int year = Integer.parseInt(args[0]) ;
                 //
設定欲判斷之年        

 

                System.out.print("西元" + year + "") ;

               

                loop4:

                if (year%4==0)//可被4除盡

                {

                        if (year%100==0)
                         //
可被4100除盡

                        {

                                if (year%400==0)
                                //
可被4100400除盡

                                {

                                        System.out.println("是閏年!") ;

                                        break loop4;

                                }                     

                                else
                                 //
可被4100除盡,不可被400除盡

                                {

                                        System.out.println("不是閏年!") ;  

                                        break loop4;

                                }

                        }

                        System.out.println("是閏年!") ;
                        //
可被4除盡,不可被100除盡                

                }

                else 
                 
//
不可被4除盡

                        System.out.println("不是閏年!");  

        }     

}

 (閱讀全文)