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