In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use Java code to write a calendar", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Java code to write a calendar" this article.
1 requirement
1. Enter the year
2. Enter the month
3. Output the calendar of a certain year and month.
2 train of thought
1. Implement to receive years and months from the console to determine whether it is a leap year (to determine whether it is a leap year: divisible by 4 but not divisible by 100, or divisible by 400)
2. Calculate the number of days of the input month
3. Calculate what day the first day of the month is
3.1 calculate the number of days between the input year and January 1, 1900
3.2 calculate the number of days before the input month (from the beginning of the year)
3.3 Sum the above two sets of data
3.4 given the number of days before the month, calculate the day of the week on the first day of the input month (starting from Monday, January 1, 1900: day of the week = 1 + day difference% 7).
4. Output the monthly calendar in format.
3 Source code import java.util.Scanner;public class index {/ / days per month public static int monthday (int month, int year) {if ((year% 4 = = 0 & & year% 100! = 0) | | year% 400 = = 0) {int [] day = {0,31,29,31,30,31,31,30,31,30,31}; return day [month] } else {int [] day = {0,31,28,31,30,31,30,31,31,30,31,30,31}; return day [month];}} / / Total days of month public static int monthdays (int month, int year) {int totaldays = 0; for (int I = 1; I)
< month; i++) { totaldays = totaldays + monthday(i, year); } return totaldays; } //距离1900年的年份总天数 public static int yeardays(int year){ int yeardays = 0; for (int i = 1900;i 0) { if (month >0 & & month < 13) {/ / the total number of days from January 1, 1900 totaldays = monthdays (month,year) + yeardays (year); System.out.println (the total number of days from the first day of year+ "year" + month+ "month to 1900:" + totaldays) System.out.println ("*" + year+ "year" + month+ "month calendar is *"); System.out.println ("one, two, three, four, five, six days"); int week = 1+totaldays%7 / / output the space for (int item1) according to the first day of the week.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.