zoukankan      html  css  js  c++  java
  • Java_Calendar小日历 wang

        

               表示博客中自带日历写的啊,都连在一起了,还是自己写的看起来顺眼些@@

     1 package com.data;
    2
    3 import java.util.Calendar;
    4 import java.util.Scanner;
    5
    6 public class Calend {
    7 /**
    8 * @param args
    9 */
    10 public static void main(String[] args) {
    11 // TODO Auto-generated method stub
    12 Calendar rightNow = Calendar.getInstance();
    13 System.out.print("请输入年份:");
    14 Scanner s1 =new Scanner(System.in);
    15 int year =s1.nextInt();
    16
    17 System.out.print("请输入月份:");
    18 Scanner s =new Scanner(System.in);
    19 int month =s.nextInt();
    20
    21 rightNow.set(Calendar.YEAR,year);
    22 rightNow.set(Calendar.MONTH, month-1);
    23 rightNow.set(Calendar.DAY_OF_MONTH,1);
    24
    25 int n = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
    26 System.out.println(month+"月共"+n+"天");
    27
    28 //int firstdayOfMonth = rightNow.get(Calendar.DAY_OF_WEEK);
    29 int maxdayOfMonth = rightNow.getActualMaximum(Calendar.DAY_OF_MONTH);
    30 //rightNow.setFirstDayOfWeek(Calendar.MONDAY);
    31
    32 System.out.println(" "+year+"年"+month+"月日历");
    33
    34 System.out.print("日"+"\t");
    35 System.out.print("一"+"\t");
    36 System.out.print("二"+"\t");
    37 System.out.print("三"+"\t");
    38 System.out.print("四"+"\t");
    39 System.out.print("五"+"\t");
    40 System.out.println("六"+"\t");
    41
    42 int m=0;
    43 for(int j=1;j<=n;j++)
    44 {
    45 rightNow.set(Calendar.DAY_OF_MONTH, j);
    46
    47 if(j==1)
    48 {
    49 m=(rightNow.get(Calendar.DAY_OF_WEEK)-1);
    50 for(int i=1;i<=m;i++)
    51 {
    52 System.out.print("-"+"\t");
    53 }
    54 }
    55 if((j+m)%7==0)
    56 {
    57 System.out.println(j+"\t");
    58 }
    59 else
    60 {
    61 System.out.print(j+"\t");
    62 }
    63 }
    64 }
    65
    66 }
  • 相关阅读:
    C++笔记(2018/2/6)
    2017级面向对象程序设计寒假作业1
    谁是你的潜在朋友
    A1095 Cars on Campus (30)(30 分)
    A1083 List Grades (25)(25 分)
    A1075 PAT Judge (25)(25 分)
    A1012 The Best Rank (25)(25 分)
    1009 说反话 (20)(20 分)
    A1055 The World's Richest(25 分)
    A1025 PAT Ranking (25)(25 分)
  • 原文地址:https://www.cnblogs.com/Turtle/p/2369833.html
Copyright © 2011-2022 走看看