在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+"不是闰年.");
}
}
}
===========================================================================
大家看看有什么意见和感想呢