黑马程序员技术交流社区

标题: 从今天起365天内有多少个休息日 [打印本页]

作者: jk7130866    时间: 2015-7-30 20:53
标题: 从今天起365天内有多少个休息日
public class Demo {

        public static void main(String[] args) {
                Calendar c=Calendar.getInstance();
                int count=0;
                for(int i=0;i<365;i++){
                c.add(Calendar.DATE, 1);
                int dayOfWek =c.get(Calendar.DAY_OF_WEEK);
                int day=c.get(Calendar.DAY_OF_MONTH);
                int month=c.get(Calendar.MONTH)+1;
                int year=c.get(Calendar.YEAR);
                if(dayOfWek==1||dayOfWek==7){
                        count++;
                        System.out.println(year+":"+month+":"+day+":"+dayOfWek+":"+count);//验证结果
                       
                }
               
                               
                }               
               
               
        }
}怎么让calendar是设置到当前时期?






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2