Calculate the number of days in a month in the current year?

Source: Internet
Author: User

Import java. util. collections;
/*
* How many days is the current year for a month in 2013?
* What is the day of the week? It is known that New Year's Day in 2013 is Tuesday.
*/
Public class Test2 {
Public static void main (string [] ARGs ){
Int month, day;
Int monthday = 0;
Boolean n = true;
Wrote input = new partition (system. In );
System. Out. println ("Enter the date of a month in December 2013 :");
Month = input. nextint ();
Day = input. nextint ();
If (month = 1 | month = 3 | month = 5 | month = 7 | month = 8
| Month = 10 | month = 12 ){
If (day> 0 & day <= 31 ){
Monthday = monthday + Day;
} Else {
N = false;
}
} Else if (month = 4 | month = 6 | month = 9 | month = 11 ){
If (day> 0 & day <= 30 ){
Monthday = monthday + Day;
} Else {
N = false;
}
} Else if (month = 2 ){
If (day> 0 & day <= 28 ){
Monthday = monthday + Day;
} Else {
N = false;
}
} Else {
N = false;
}
For (INT I = 0; I <month; I ++ ){
If (I = 1 | I = 3 | I = 5 | I = 7 | I = 8 | I = 10
| I = 12 ){
Monthday = monthday + 31;
} Else if (I = 4 | I = 6 | I = 9 | I = 11 ){
Monthday = monthday + 30;
} Else if (I = 2 ){
Monthday = monthday + 28;
}
}
If (n ){
System. Out. println ("2013" + month + "month" + day + "is the day of the current year"
+ Monthday + "day ");
Switch (monthday % 7 ){
Case 0 :{
System. Out. println ("Monday ");
Break;
}
Case 1 :{
System. Out. println ("Tuesday ");
Break;
}
Case 2 :{
System. Out. println ("Wednesday ");
Break;
}
Case 3 :{
System. Out. println ("Thursday ");
Break;
}
Case 4 :{
System. Out. println ("Friday ");
Break;
}
Case 5 :{
System. Out. println ("Saturday ");
Break;
}
Case 6 :{
System. Out. println ("Sunday ");
Break;
}
Default:
Break;
}
} Else {
System. Out. println ("the input date does not meet the condition ");
}
}
}

Calculate the number of days in a month in the current year?

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.