当前位置:网站首页>Nested if selection structure and switch selection structure
Nested if selection structure and switch selection structure
2022-07-25 04:01:00 【Raise your eyes and look far away】
nesting if Selection structure
nesting if structure : In a if The selection structure contains a complete if Selection structure
The law of execution : Execute the corresponding code according to whether the condition is true
The acquisition of random numbers :
Math.random(): Randomly generate a greater than or equal to 0.0 Less than 1.0 Of double Data of type
Math.random()*10: Randomly generate a greater than or equal to 0.0 Less than 10.0 Of double Data of type
(int)(Math.random()*10): Randomly generate a greater than or equal to 0 Less than 10 Of int Data of type
summary : Pick one at random [num1,num2) Between int Type integer (num2>num1)
int num =(int)(Math.random()*(num2-num1)+num1);
eg:
// Randomly generate a greater than or equal to 19, Less than 51 Between int Number of types
int num4 = (int) (Math.random() * 32 + 19);
System.out.println(num4);
switch Selection structure
switch choice :
Rule of grammar :
switch ( expression ){
case Constant 1:
// sentence ;
break;
case Constant 2:
// sentence ;
break;
case Constant 3:
// sentence ;
break;
......
case Constant n:
// sentence ;
break;
default:
// sentence ;
break;
}
The law of execution :
1) Match according to the value of the expression case The following constant values ,
After matching, execute the corresponding statement , Finish executing the following statement , perform break,
End the whole thing switch structure , So let's keep going switch Select the code after the structure
2) If the value of the expression does not match the value of all constants ,
Is executed default The words in it ,
Execute... After execution break Quit the whole switch Selection structure
Be careful :
1) The value of an expression can be int、short、byte、char、 Enumeration type 、String(JDK1.7 Later support )
2)case The following constant values cannot be the same
3)default Sentences can be left blank . If you write that the value of the expression does not match all constant values ,
Is executed default The sentence in .default Statements can be written anywhere , Generally written in the book switch Last bit of Set up .
4)switch Choosing a structure can only deal with the case of equivalent judgment
5)break The function of is to end the whole switch Selection structure ,
If there is a lack of , The code will continue to run down , Carry out the next case The sentence in , This phenomenon is called " through The phenomenon ".
case Penetration phenomenon can be used reasonably
Penetration phenomenon eg:
/*
* Enter month , Output season
*
* 12 1 2 In the winter 3 4 5 In the spring 6 7 8 In the summer 9 10 11 In the fall
*/
int month=4;
switch(month){
case 12:
//System.out.println(" In the winter ");
//break;
case 1:
//System.out.println(" In the winter ");
//break;
case 2:
System.out.println(" In the winter ");
break;
case 3:
//System.out.println(" In the spring ");
//break;
case 4:
//System.out.println(" In the spring ");
//break;
case 5:
System.out.println(" In the spring ");
break;
case 6:
//System.out.println(" In the summer ");
//break;
case 7:
//System.out.println(" In the summer ");
//break;
case 8:
System.out.println(" In the summer ");
break;
case 9:
//System.out.println(" In the fall ");
//break;
case 10:
//System.out.println(" In the fall ");
//break;
case 11:
System.out.println(" In the fall ");
break;effect :
边栏推荐
- One question per day
- Implementing DDD based on ABP -- domain logic and application logic
- Skywalking distributed link tracking, related graphics, DLJD, cat
- 考研经历
- 01_ Education 3
- 数据中台建设(一):数据中台出现的背景
- [golang] golang realizes sending wechat service number template messages
- 场景之在线人数或者粉丝查询实现
- Force button brushing question 61. rotating linked list
- The difference between apply, call and bind
猜你喜欢
![[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y](/img/42/5a3ec5bbf888a2d29b4f556dd94b10.png)
[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y

Has baozi ever played in the multi merchant system?

Installation and tutorial of MATLAB curling simulation game

Fiddler grabs packets and displays err_ TUNNEL_ CONNECTION_ FAILED

How should enterprise users choose aiops or APM?

MySQL select query part 2

Acwing 870. approximate number

A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png

Pytorch deep learning practice lesson 8 importing data

Array the same value of key and merge the value value (collation)
随机推荐
Leetcode.745. prefix and suffix search____ Double dictionary tree + double pointer
Wechat applet access wechat payment process
Force deduction question 3
What should testers do if they encounter a bug that is difficult to reproduce?
Function method encapsulation -- mutual conversion of image types qpixmap, qimage and mat
Emergency response stack
Tiktok live broadcast brings goods to help the industry go to sea, and Fastdata observation industry boutique salon helps the ecological development
Detailed explanation of kubernetes network plug-in - flannel chapter
Array the same value of key and merge the value value (collation)
Debezium series: Show slave status view the possible different situations of master-slave delay
Servlet personal practice notes (I)
Debezium series: when there are a large number of DML operations in the record source database, the debezium consumption data time lags behind the data generation time by several hours
Advantages and disadvantages of zero trust security
Postgraduate entrance examination experience
Moveit2 - 10.urdf and SRDF
[Flink] transform operator map
301. Delete invalid brackets
Roleapp focuses on Web3 and opens the door of Web3 with the key of "data can be held"
Optimization of MySQL sorting index fields
MySQL select query part 2