The programmer must do 50 questions 4: enter a day of a certain year to determine the day of the year ?, 50 days

Source: Internet
Author: User

The programmer must do 50 questions 4: enter a day of a certain year to determine the day of the year ?, 50 days

Package pwd;/*** the programmer must do 50 questions 4: enter a day of a certain year to determine the day of the year? * <P> @ author SunJian </p> * <p> date: January 1, October 20, 2017 </p> * <p> QQ: 330160114 </p> * <p> company: sihai xingtang </p> * <p> site: www.ccshxt.com </p> */public class DateCount {public static void main (String [] args) {// enter String input = "20171020" on the keyboard. // The day of the year int howManyDates = 0; // parse the year, month, and day int year = Integer. parseInt (input. substring (0, 4); int month = Integer. parseInt (input. substring (4, 6); int date = Integer. parseInt (input. substr Ing (6, 8); boolean run = false; // determines whether it is a leap year if (year % 100 = 0 & year % 4 = 0) & year % 400! = 0) {run = true;} for (int m = 1; m <month; m ++) {switch (m) {case 1: howManyDates + = 31; break; case 2: if (run) {// leap year, October day howManyDates + = 29;} else {// non-leap year, October day howManyDates + = 28;} break; case 3: howManyDates + = 31; break; case 4: howManyDates + = 30; break; case 5: howManyDates + = 31; break; case 6: howManyDates + = 30; break; case 7: howManyDates + = 31; break; case 8: howManyDates + = 31; break; case 9: howManyDates + = 30; break; case 10: howManyDates + = 31; break; case 11: howManyDates + = 30; break; case 12: howManyDates + = 31; break; default: System. out. println ("error") ;}} howManyDates = howManyDates + date; System. out. println (input + "is the" + year + "year" + howManyDates + "day ");}}

  

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.