Home >Java >javaTutorial >The meaning of case in java
In Java, case is the keyword of the switch statement, which is used to specify the code block to be executed. It is executed when the case value matches the value of the switch expression. The syntax is: switch(expression) { case value 1: // Code block 1; break; case value 2: // Code block 2; break; ... default: // Default code block }. Each case value must be unique. You can use the break statement to exit the switch statement. Without break, subsequent cases will continue to be executed.
The meaning of case in Java
case is a keyword used in the switch statement in Java .
Function:
Grammar:
<code class="java">switch(switch_expression) { case value1: // 代码块 1 break; case value2: // 代码块 2 break; // 其他 case 子句 ... default: // 默认代码块 }</code>
Example:
<code class="java">switch (grade) { case 'A': System.out.println("优秀"); break; case 'B': System.out.println("良好"); break; case 'C': System.out.println("及格"); break; default: System.out.println("不及格"); }</code>
Notes:
The above is the detailed content of The meaning of case in java. For more information, please follow other related articles on the PHP Chinese website!