Java Basics Hardening the 97:calendar class to get the number of days of February in any year of the case

Source: Internet
Author: User

1. Analysis:

(1) Keyboard entry for any year

(2) Set the date of the Calendar object

Year: That is (1) the data entered

Month: Yes 2 (March)

Day: Yes 1

(3) Push the time forward one day, the last day of February

(4) Output this day

2. code example:

1  Packagecn.itcast_03;2 3 ImportJava.util.Calendar;4 ImportJava.util.Scanner;5 6 /*7 * Get how many days in February of any year8  * 9 * Analysis:Ten * A: Keyboard entry for any year One * B: Set Calendar object's Month day A * Year is the data of a input - * Month is 2 - * Day is 1 the * C: Push the time forward one day, the last day of February - * D: Get this day's output -  */ -  Public classCalendartest { +      Public Static voidMain (string[] args) { -         //Keyboard entry for any year +Scanner sc =NewScanner (system.in); ASystem.out.println ("Please enter the year:"); at         intYear =sc.nextint (); -  -         //set Calendar object's Month day -Calendar C =calendar.getinstance (); -C.set (year, 2, 1);//This is actually the March 1 of the year. -         //Push the time forward one day, the last day of February inC.add (Calendar.date, 1); -  to         //get this day's output + System.out.println (C.get (calendar.date)); -     } the}

The results are as follows:

Java Basics Hardening the 97:calendar class to get the number of days of February in any year of the case

Related Article

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.