java — 簡單的日曆

來源:互聯網
上載者:User

標籤:instance   ring   簡單   for   get   static   string   max   i++   

 

import java.util.Calendar;

import java.util.Scanner;

 class Demo {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        System.out.print("請輸入年份:");

        int year = scan.nextInt();

        System.out.print("請輸入月份:");

        int month = scan.nextInt();

        System.out.println("\n\n\t\t"+year + "年" + month + "月\n\n");

        System.out.println("周日\t周一\t周二\t周三\t周四\t周五\t周六");

        Calendar c = Calendar.getInstance();

 
        c.set(year, month-1, 1);

        int weekday = c.get(Calendar.DAY_OF_WEEK);

    

        int maxDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);

        int temp = 0;


        for (int i = 1; i < weekday; i++){

            System.out.print("*\t");

            temp++;

        }


        for (int i = 1; i <= maxDay; i++){

            System.out.print(i + "\t");
            temp++;
            if (temp%7 == 0){
                    System.out.println();
            }

        }

    }

}

java — 簡單的日曆

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.