美文网首页
输入日期打印日历

输入日期打印日历

作者: 吴鹏608 | 来源:发表于2018-01-17 22:28 被阅读0次
    package com.company;
    
    import java.util.Calendar;
    import java.util.Scanner;
    
    public class calendardate {
        public static void main(String[] args) {
            System.out.println("请输入年份");
            Scanner scanner = new Scanner(System.in);
            int year = scanner.nextInt();
            System.out.println("请输入月份");
            int month = scanner.nextInt();
            System.out.println("请输入日期");
            int date = scanner.nextInt();
            Calendar calendar = Calendar.getInstance();
            calendar.set(year,month-1,1);
            int day = calendar.getActualMaximum(Calendar.DATE);
           int xday = calendar.get(Calendar.DAY_OF_WEEK);
            System.out.println(xday);
            System.out.println("日\t一\t二\t三\t四\t五\t六");
            int index = 1;
            for (int i = 0;i<day+xday-1;i++){
    
                if (i<xday-1){
                    System.out.print("\t");
                }
                else {
                    if (date == index){
                        System.out.print(index+"*"+"\t");
                    }else {
                        System.out.print(index+"\t");
                    }
                    if ((i+1)%7 == 0){
                        System.out.println();
                    }
                    index++;
                }
    
            }
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:输入日期打印日历

          本文链接:https://www.haomeiwen.com/subject/ytdpoxtx.html