Home > Java > javaTutorial > body text

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.

王林
Release: 2023-05-09 16:01:09
forward
697 people have browsed it

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template