Basic usage and usage

Source: Internet
Author: User

Basic usage and usage

Requirement: enter a month on the keyboard and output the season corresponding to the month.

Four seasons in a year

3, 4, 5 spring

6, 7, 8 summer

9, 10, 11 Autumn

12, 1, 2 Winter

Analysis:

A: enter A month on the keyboard.

B: determines the month. The corresponding season is output based on the month.

Public class Test2 {public static void main (String [] args) {// enter a month on the keyboard, and use week SC = new week (System. in); // receives the data System. out. println ("Enter the month (1-12):"); int month = SC. nextInt (); switch (month) {case 1: case 2: case 12: System. out. println ("Winter"); break; case 3: case 4: case 5: System. out. println ("Spring"); break; case 6: case 7: case 8: System. out. println ("Summer"); break; case 9: case 10: case 11: System. out. println ("Autumn"); break; default: System. out. println ("the month you entered is incorrect"); break ;}}}

Of course, there are many other methods. Here we only demonstrate one

 

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.