Home  >  Article  >  Java  >  What is the original sentence of the next sentence? This sentence is a title and needs to be supplemented with background information before it can be rewritten specifically.

What is the original sentence of the next sentence? This sentence is a title and needs to be supplemented with background information before it can be rewritten specifically.

王林
王林forward
2023-05-09 16:01:09680browse

First explain this problem from the principle:

switch(expression)

{ case constant expression 1: statement 1;

....

case constant expression 2: statement 2;

default: statement; }

1.default means that if there is no matching case, it will be executed. Default is not necessary.

2. The statement after the case does not need braces.

3. The judgment condition of the switch statement can accept int, byte, char, short, but cannot accept other types.

4. Once the case matches, the following program codes will be executed sequentially, regardless of whether the subsequent cases match, until break is encountered. This feature can be used to allow several cases to execute the same statement.

Principles are principles, Here are a few confusing examples.

1. Standard type (case is followed by break statement)

int i=3;
switch(i)
{
case 1:
System.out.println(1);
break;
case 2:
System.out.println(2);
break;
case 3 :
System.out.println(3);
break;
default:
System.out.println("default");
break;
}

Output result:

3

The above is the detailed content of What is the original sentence of the next sentence? This sentence is a title and needs to be supplemented with background information before it can be rewritten specifically.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete