Java programming calculates the day of the year, and java programming calculates

Source: Internet
Author: User

Java programming calculates the day of the year, and java programming calculates

You can directly copy and run it.

Package year; import java. util. week; public class year {public static void main (String [] args) {// TODO Auto-generated method stub year y = new year (); y. fun ();} public void fun () {String str = shuru (); int year = Integer. parseInt (str. split ("") [0]); int month = Integer. parseInt (str. split ("") [1]); int day = Integer. parseInt (str. split ("") [2]); jisuan (year, month, day);} private String shuru (){ System. out. print ("separated by spaces in the middle of the input year, month, and day:"); Second s = new second (System. in); return s. nextLine ();} private void jisuan (int year, int month, int day) {int I = 0; int j = 0; // if (year % 400 = 0 | year % 4 = 0 & year % 100! = 0) {switch (month) {case 12: I + = 31; case 11: I + = 30; case 10: I + = 31; case 9: I + = 30; case 8: I + = 31; case 7: I + = 31; case 6: I + = 30; case 5: I + = 31; case 4: I + = 30; case 3: I + = 31; case 2: I + = 28; case 1: I + = 31 ;} if (month = 1 | month = 3 | month = 5 | month = 7 | month = 8 | month = 10 | month = = 12) {j = 31-day; System. out. println (I-j);} else if (month = 2) {j = 28-day; System. out. println (I-j);} else {j = 30-day; System. out. println (I-j) ;}} else {switch (month) {case 12: I + = 31; case 11: I + = 30; case 10: I + = 31; case 9: I + = 30; case 8: I + = 31; case 7: I + = 31; case 6: I + = 30; case 5: I + = 31; case 4: I + = 30; case 3: I + = 31; case 2: I + = 29; case 1: I + = 31 ;} if (month = 1 | month = 3 | month = 5 | month = 7 | month = 8 | month = 10 | month = = 12) {j = 31-day; System. out. println (I-j);} else if (month = 2) {j = 28-day; System. out. println (I-j);} else {j = 30-day; System. out. println (I-j );}}}}

For example, input: 1994 3 28

Output: 88

January 1, 88th.

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.