计算某一天是星期的程序!


Posted on April 23, 2007


import java.util.*;
public class calander
{
    public static void main(String[] args)
    {
        String   sdate = "2009-04-22";
        int   syear   =   Integer.parseInt(sdate.substring(0,   4));
        int   smonth   =   Integer.parseInt(sdate.substring(5,   7))   -   1;
        int   sday   =   Integer.parseInt(sdate.substring(8,   10));
        GregorianCalendar   cal   =   new   GregorianCalendar();
        cal.set(syear,   smonth,   sday);
        int week   =   cal.get(java.util.Calendar.DAY_OF_WEEK);
        switch (week)
        {
        case 1:
            System.out.print("星期日");
            break;
        case 2:
            System.out.print("星期一");
            break;
        case 3:
            System.out.print("星期二");
            break;
        case 4:
            System.out.print("星期三");
            break;
        case 5:
            System.out.print("星期四");
            break;
        case 6:
            System.out.print("星期五");
            break;
        case 7:
            System.out.print("星期六");
            break;
        }
    }
}

标签:N/A

 

在线学习答案查询入口
微信扫码联系
微信扫码联系