Java implementation input A certain date of the year, to determine this day is the first days of the year?

Source: Internet
Author: User
3. Enter a certain date of the year, to determine the day is the first days of the year.
Import Java.util.Scanner;
public class year{
public static void Main (string[] args) {
Scanner scan = new Scanner (system.in);
int ye =0, Mon = 1, day = 1;
int i;
int to = 0;
int a[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
for (;;) {
System.out.print ("Please enter Year:");
Ye = Scan.nextint ();
if (ye<0) {
SYSTEM.OUT.PRINTLN ("Year should be greater than 0, please re-enter.") ");
Continue
}else{
Break
}
}
for (;;) {
System.out.print ("Please enter the month:");
Mon = Scan.nextint ();
if (mon<0) {
SYSTEM.OUT.PRINTLN ("Month should be between 1-12, please re-enter.") ");
Continue
}else{
Break
}
}
for (;;) {
System.out.print ("Please enter the day:");
Day = Scan.nextint ();
if ((ye%400 = = 0 && ye%100 = 0) | | ye%4 = 0) {//Determine if it is a leap year
a[2]=29;

}
if (Day > A[mon]) {
SYSTEM.OUT.PRINTLN (the date should be a valid value, please re-enter it.) ");
Continue
}else{
if (Mon = = 1) {//
to = day;
}else{
for (i = 0;i <= mon-1; i++) {
to + + a[i];
}
to + = day;
}

System.out.println ("The day is the first of the year" +to+ "Day");
Break
}
}
}

}

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.