The Java calendar displays the year, month

Source: Internet
Author: User

Import Java.util.Scanner;

Class Calendarmain
{
Main function entry
public static void Main (string[] args)
{
SYSTEM.OUT.PRINTLN ("* * * * * Please enter the date (format: 2011-01) * * * * *);
Scanner sc = new Scanner (system.in);
String ym = Sc.next ();
Intercept string
string[] Yearmonth = Ym.split ("-");
Convert a string into an integer type
int year = integer.parseint (yearmonth [0]);
int month = Integer.parseint (yearmonth [1]);
Year.fun (year);
Month.fun (month,year);
}
}

Get the number of leap years
Class year
{
Number of leap years
static int leapyear = 0;

public static void Fun (int year) {
if (Year > 1990 && year <10000) {
while (year >= 1990) {
if (year% 4 = = 0 && Year% 100! = 0 | | (Year% 400 ==0)) {
Leapyear + +;
}
Year--;
}
}else{
System.out.println ("Please enter the year of the query greater than or equal to 1990 years!");
}
}
}

Get one months how many days and total days
Class Month
{
public static void Fun (int. month,int year) {
int monthday = 0;
Year y = New Year ();
int days = Y.leapyear + (year-1990) *365;
if (Month > 0 && month <=12) {
for (int i = 1;i <= month;i++) {
if (I < 8 && i! = 2) {
Days + = i% 2 = = 1? 31:30;
MonthDay = i% 2 = = 1? 31:30;
}
if (i > 7) {
Days + = i% 2 = = 1? 30:31;
MonthDay = i% 2 = = 1? 30:31;
}
if (i = = 2) {
if (year% 4 = = 0 && Year% 100! = 0 | | (Year% 400 ==0)) {
Days + = 28;
MonthDay = 29;
}else{
Days + = 28;
MonthDay = 28;
}
}
}
Show.mothed (Days,monthday);
}else{
System.out.println ("Please enter the correct month!") ");
}
}
}

Show Calendar
Class Show
{
public static void mothed (int days, int monthday) {
Plus one means starting from Monday
Int week = (days-monthday)% 7 + 1;

System.out.println ("\ n Sunday" + "\ t Monday" + "\ t Tuesday" + "\ t Wednesday" + "\ t Thursday" + "\ t Friday" + "\ t Saturday");
for (int i = 1;i <= monthday + week; i++)
{
if (I <= week) {
System.out.print ("" + "*" + "\ T");
}else{
if ((I-week) < 10) {
System.out.print ("" + (I-week) + "\ T");
}else{
System.out.print ((i-week) + "\ T");
}
}
if (i%7 = = 0) {
System.out.print ("\ n");
}
}
}
}

The Java calendar displays the year, month

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.