大家来帮帮忙 
怎么用JAVA实现: 
输入一个随机的日期,可以得到这年是平年还是闰年,并且还要算出离当年的1月1日有多少天。
这还得考虑每个月的天数
怎么弄啊??
帮帮忙啊

解决方案 »

  1.   

    我的那个答复不行吗?如何判断闰年 
    1。能被4整除而不能被100整除。 
    2。能被400整除。 
    if ((year%4 == 0) && (year%100 != 0) && (year%400 == 0))
    至于如何计算差多少天  看看我的这个帖子吧: 
    http://blog.csdn.net/justinavril/archive/2008/09/06/2891266.aspx
      

  2.   

    public class CalendarTester {
        static Calendar cal = Calendar.getInstance();    public static boolean isLeapYear(Date date) {
            cal.setTime(date);
            return (cal.get(Calendar.YEAR) % 4 == 0)
                    || (cal.get(Calendar.YEAR) % 400 == 0);
        }    public static int countDays(Date date) {
            cal.setTime(date);
            return cal.get(Calendar.DAY_OF_YEAR);
        }    public static void main(String[] args) {
            Date now = new Date();
            System.out.println("IsLeapYear : " + isLeapYear(now));
            System.out.println("total day : " + countDays(now));
        }
    }
      

  3.   

    public static boolean isLeapYear(Date date) {
            cal.setTime(date);
            return (cal.get(Calendar.YEAR) % 4 == 0 && cal.get(Calendar.YEAR) % 100 != 0)
                    || (cal.get(Calendar.YEAR) % 400 == 0);
        }