同样一个问题的两种 java 实现代码 的比较

在csdn上面看见一个小孩子(估计是学生),写的个程序,是做闰年判断的,我正好没事做(プロジェクッとが暇です)

就给他改了一下程序,程序很简单,但是我想大家能不能从这两个程序中间看出什么来,至少学生和我们专业coder写东西的风格就不一样吧

小孩子的代码:

===============================================================

public class T

      public static void main(String[] args)
       {
 
          boolean check=false;
          for(int year=1600;year<=2007;year++)
           {  
        check=false;
                if(year%4==0&&year%100!=0)
                    check=true;
                else
   {
if(year%400==0)
                        check=true;
                   }
               if(check)      
                System.out.println(year+"是闰年.");
               else
                System.out.println(year+"不是闰年.");

           }
      }
}
===========================================================================

我的代码: 

===========================================================================

public class Year
{  
        private boolean check;
        public boolean getYear (int year) {
                check = false;
                if((0 == year%4) && (0 != year%100)) {
                    check = true;
                }
                if (0 == year%400){
                    check = true;   
                }
                return check;                   
            }  
           
        public boolean checkArgs (String arg) {
                if (null != args) {
                    return true;
                    }
                 return false;  
            }    
      public  static void main(String args[]) {
        int yearStart = 0;
        int yearEnd = 0;
        if (true == checkArgs(args[0])) {
                yearStart =  Integer.valueOf(args[0]).intValue();
            }
        if (true == checkArgs(args[1])) {
                yearStart =  Integer.valueOf(args[1]).intValue();
            }   
        Year test = new Year();
          for(int year = yearStart; year <= yearEnd; year++)  {      
               if(true == test.getYear(year))      
                    System.out.println(year+"是闰年.");
               else
                    System.out.println(year+"不是闰年.");
           }
      }
}
===========================================================================

大家看看有什么意见和感想呢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值