This part is also familiar, but you need to pay attention to the use of switch statements.
Public class chose {public static void main (string ARGs []) {int grade = 3; Switch (grade) {Case 3: system. Out. println ("excellent performance! "); Break; Case 2: system. Out. println (" pass! "); Break; Case 1: system. Out. println (" need to be repaired again! "); Break; Case 0: system. Out. println (" need to be repaired again! "); Break; default: system. Out. println (" the score is incorrect! "); Break ;}}}
Note the following two points:
1. Break statement
Add the break statement after each case, which indicates that the entire switch branch is exited. If you do not add a break,ProgramIt starts from the first place that meets the case conditions, and will be executed in subsequent cases.
2. Set the default statement
For some data that does not meet the conditions, the default statement must be used to determine the data, otherwise there is no mechanism to process the abnormal data.
Switch is used as follows:
public class chose {public static void main (string ARGs []) {int grade = 3; Switch (grade) {Case 3: system. out. println ("Excellent! "); Break; Case 2: system. Out. println (" pass! "); Break; Case 1: system. Out. println (" need to be repaired again! "); Break; Case 0: system. Out. println (" need to be repaired again! "); Break; default: system. Out. println (" the score is incorrect! "); Break ;}}