Java implementation of the simple perpetual calendar code _java

Source: Internet
Author: User

This article illustrates the simple perpetual calendar of Java implementations. Share to everyone for your reference, specific as follows:

Import Java.util.Scanner;
 public class Printcalendar {public static void main (string[] args) {int years = 0;
 int month = 0; 
 int days = 0;
 Boolean isrun = false;
 From the console input year, the month Scanner input = new Scanner (system.in);
 System.out.print ("Please enter the Year:");
 years = Input.nextint ();
 System.out.print ("Please enter the month:");
 month = Input.nextint ();
 System.out.println ("\n*********" +years+ "year" +month+ "calendars table ************"); Determine if it is a leap year if ((years% 4 = 0 && years% 100!= 0) | | (years% 400 = 0))
 {Isrun = true; int totaldays = 0; Count of days//calculate distance from January 1, 1900 for (int i = 1900 I < years; i++) {if ((i% 4 = 0 && i% 100!= 0) | | (i% 400 = 0))
 {totaldays = totaldays + 366;
 }else{totaldays = totaldays + 365;
 an int beforedays = 0; According to the number of days for (int j = 1; J <= Month + +) {switch (j) {case 1:case 3:case 5:case 7:case 8:case 10:case 1
 2:days = 31;
 Break
 Case 4:case 6:case 9:case 11:days = 30;
 Break
 Case 2:if (isrun) {days = 29; }else{Days = 28;
 } default:System.out.println ("Input month incorrect!!");
 } if (J < month) {beforedays = beforedays + days; } totaldays = Totaldays + beforedays;
 The current total number of int firstdayofmonth = 0;
 int temp = 1 + totaldays% 7;
 if (temp = 7) {firstdayofmonth = 0;//Monday}else{Firstdayofmonth = temp;
 /* Output calendar/System.out.println ("Sunday \ t Monday \ Tuesday \ Wednesday \ Thursday \ t Friday \ Saturday");
 for (int k = 0; k < firstdayofmonth; k++) {System.out.print ("T");
 for (int m = 1; m <= days; m++) {System.out.print (M + "t");
 if ((Totaldays + m)% 7 = 6) {System.out.print ("\ n");

 }
 }
 }
}

About the calendar of the production of interested friends can also refer to the site online tools:

Online Perpetual calendar

Web Calendar

I hope this article will help you with Java programming.

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.