日期:2014-05-20  浏览次数:20722 次

看下这个Main函数调用错在哪?
[code=Java][/code]
import java.util.Calendar;
import java.util.GregorianCalendar;
public class AA {

public static void main(String[] args)  
{
if(args!=null && args.length>0) 
{
String dateArray[] = args[0].split(",");
 
Calendar calendar = new GregorianCalendar(); 
Calendar calendar1 = new GregorianCalendar(); 
 
 
calendar.set(Integer.parseInt(dateArray[0]),
Integer.parseInt(dateArray[1]),
Integer.parseInt(dateArray[2]));
long time1=calendar.getTimeInMillis();
calendar1.set(Integer.parseInt(dateArray[3]),
Integer.parseInt(dateArray[4]), 
Integer.parseInt(dateArray[5])); 
long time2=calendar1.getTimeInMillis();  
long 相隔天数=(time2-time1)/(1000*60*60*24);
System.out.println(相隔天数);
}  
}
}

程序功能:
键盘输入两个时间,如:1987,4,5 1998,8,7 求出相隔的天数


------解决方案--------------------
Java code

import java.util.Calendar; 
import java.util.GregorianCalendar;
public class Test { 
  public static void main(String[] args) {
        if(args!=null && args.length==2) { 
            String dateArray1[] = args[0].split(",");
            String dateArray2[] = args[1].split(",");
            Calendar calendar2 = new GregorianCalendar(); 
            Calendar calendar1 = new GregorianCalendar(); 
          
          calendar1.set(Integer.parseInt(dateArray1[0]), Integer.parseInt(dateArray1[1]), Integer.parseInt(dateArray1[2])); 
             long time1=calendar1.getTimeInMillis(); 
         
             calendar2.set(Integer.parseInt(dateArray2[0]), Integer.parseInt(dateArray2[1]), Integer.parseInt(dateArray2[2])); 
            long time2=calendar2.getTimeInMillis();  
          
          long day=(time2-time1)/(1000*60*60*24); 
          System.out.println("相隔天数:" + day); 
        }  
    } 
}