当前位置:网站首页>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 :
边栏推荐
- Display: the function and effect of align content, justify content and align items under flex
- Project launch process of software testing technology
- C language: string processing function
- Force deduction brush question 7. Integer inversion
- The sixth day of brushing questions with force deduction
- 场景之在线人数或者粉丝查询实现
- Execution flow control of shell
- Traditional architecture of enterprise digital transformation to medium platform micro service architecture
- Niuke interview high frequency list (group 1) difficulty: simple & medium
- 基于ABP实现DDD--领域逻辑和应用逻辑
猜你喜欢

Solve "nothing added to commit but untracked files present"“

Emergency response stack

Yuntu says digital asset chain: your God of digital asset property protection

ES(8.1)认证题目

Moveit2 - 8. Motion planning API
![Advanced numbers | [calculus of multivariate function] chain derivation method, implicit function derivation method, total differential form invariance, multivariate function extremum](/img/a8/c18118bb97118ebc4e1af7a08337b4.png)
Advanced numbers | [calculus of multivariate function] chain derivation method, implicit function derivation method, total differential form invariance, multivariate function extremum

Multithreading advanced Step2

How should enterprise users choose aiops or APM?

Force the resumption of game 302 of the week

A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png
随机推荐
Es- retrieve the selected field from the search
Force deduction brush question 14. Longest common prefix
Moveit2 - 8. Motion planning API
Unity: text input box for numerical judgment
基于SSH婴幼儿产品销售系统
Shell string
01_ Education 1
[matlab] solve the mex error there was a problem creating the mex file for real time execution, please ensure y
Creativity: Modern Art anonymous oil painting AI works presentation
LeetCode. 302 weekly games___ 03_ 6121. Query the number smaller than k after cutting the number____ sort
MySQL eight shares
[laser principle and application -5]: laser diode LD (laser diode) and laser diode driver (LD driver)
Implementation of online number or fan query of the scene
C language: string processing function
High temperature in Britain: two airport runways were burnt out, and several railways were restricted to ensure safety
Huawei od maximum consumption JS
P100 MSSQL database penetration test of secondary vocational network security skills competition
2022-07-19 study notes of group 5 self-cultivation class (every day)
What should testers do if they encounter a bug that is difficult to reproduce?
Deeply understand the connection state and reliable mechanism of TCP protocol