The return value of an expression in switch is one of the byte short char int enumeration strings.
The value in the case must be a constant, and the value in the case clause is different.
Default is optional, when no matching value in case jumps to default
Break jumps out of a switch loop statement after executing a case statement. Without break, the program executes to the end of the switch. (In other words, if a case is executed, there is no definition Break,switch will execute all of the rest of the following or the default statement)
Scanner Scanner = new Scanner (system.in);
System.out.println ("Enter year:");
int year = Scanner.nextint ();
System.out.println ("Enter month:");
int month = Scanner.nextint ();
System.out.println ("Enter day:");
int day = Scanner.nextint ();
int sumday = 0;
Switch (month) {
Case 12:
Sumday + = 30;
Case 11:
Sumday + = 31;
Case 10:
Sumday + = 30;
Case 9:
Sumday + = 31;
Case 8:
Sumday + = 31;
Case 7:
Sumday + = 30;
Case 6:
Sumday + = 31;
Case 5:
Sumday + = 30;
Case 4:
Sumday + = 31;
Case 3:
if (year% 4 = = 0 && year%!! = 0 | | year% 400 = = 0)
Sumday + = 29;
Else
Sumday + = 28;
Case 2:
Sumday + = 31;
Case 1:
Sumday + = day;
}
SYSTEM.OUT.PRINTLN (Year + "years" + month + "Month" + Day + "date is this year's first" + Sumday
+ "Day");
Above for example you entered May, the code will go into case 5: Then the code does not have break,case behind the code will be executed.
Java Personal Learning Note: switch