当前位置:网站首页>Branch statement of process control
Branch statement of process control
2022-04-23 14:26:00 【Zinksl】
:::info
according to Forgetting curve : If there is no record and review ,6 Days later, I will forget 75% The content of
Reading notes are a tool to help you record and review , Don't stick to form , Its core is : Record 、 Look over 、 reflection
:::
Overview of process control statements
In the default program, it is a sequential structure , From top to bottom ; Use mind mapping , Structured core concepts .
Branch statement
if sentence ( The final judgment condition must be : Boolean type value )
1 Simple if Sentence format :
Sentence format :
if ( Judge the condition ){
Statement of body ; // If the judgment condition is true, execute the body of the statement ;
}
int nub1 = 1;
int nub2 = 2;
if(nub1>nub2){
System.out.println(" Executed the body of the statement "); // The judgment condition is false, This sentence does not execute ;
}
2 if…else Sentence format
Sentence format :
if ( Judge the condition ){
Statement of body 1; // If the judgment condition is true, execute the body of the statement 1;
}else{
Statement of body 2; // If the judgment condition is not tenable, execute the body of the statement 2;
}
int nub1 = 1;
int nub2 = 2;
if(nub1>nub2){
System.out.println(" Executed the body of the statement 1"); // The judgment condition is false, This sentence does not have an executive ;
}else{
System.out.println(" Executed the body of the statement 2"); // The judgment condition is false, Execute this sentence ;
}
3 if…else if…else… Sentence format
Sentence format :
if ( Judge the condition 1){
Statement of body 1; // If the judgment condition is true, execute the body of the statement 1;
}else if( Judge the condition 2){
Statement of body 2; // Judge the condition 1 Don't set up , Judge the condition 2 establish , Execute statement body 2;
}else{
Statement of body 3; // Judge the condition 1 and 2 No execution statement body 3;
}
/* Exam rewards : fraction >=90: Reward a bike 90> fraction >=80: Reward the amusement park for a one-day trip 80> fraction : A good beating */
public class IfTest {
public static void main(String[] args) {
int chengji;
Scanner sc = new Scanner(System.in);
System.out.println(" Please enter the grade :");
chengji = sc.nextInt();
if (chengji <=100 && chengji>=0){
if (chengji>=90){
System.out.println(" Congratulations ! Reward a bike !");
}else if (chengji>=80 && chengji<90){
System.out.println(" Congratulations ! Reward the amusement park for a one-day trip !");
}else{
System.out.println(" Come on, take a beating !");
}
}else{
System.out.println(" The score is wrong !");
}
}
}
switch sentence
switch Sentence format :
switch(){
case 1:
Statement of body 1;
break;
case 2:
Statement of body 2;
break;
case 3:
Statement of body 3;
break;
.
.
.
default:
The default value is the body of the statement ;
break;}
1 matters needing attention :jdk Characteristics and week Value range of
- Basic types :byte、short、int、long
- Reference type :jdk5 Start , Enumeration types are allowed ;jdk7 Start , allow String
- jdk14 Start allowing , One case Followed by multiple values :case 1,2,3:
- if And switch choose : The judgment of scope is if; Fixed value judgment switch;
switch(week){
case 1:
// Statement of body 1;
break;
case 2:
// Statement of body 2;
break;
case 3:
// Statement of body 3;
break;
default:
// Default statement body ;
break;
}
2 case through ( You can optimize the code )
case Penetration example : If there are multiple repeated statement bodies, you can use case through
switch(week){
case 1:
case 2:
case 3:
// Repeat the sentence body ;
break;
default:
break;
}
3 jdk14 New features in the future ( You can optimize the code )
case Penetration example : If there are multiple repeated statement bodies, you can use case through
switch(week){
case 1,2,3:
// Repeat the sentence body ;
break;
default:
break;
}
Be careful : The most commonly used logical operator in programming is : Short circuit and (&&)、 Short circuit or (||) He Fei (!); It can improve the operation efficiency of the code ;
版权声明
本文为[Zinksl]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412046370.html
边栏推荐
猜你喜欢
MQ-2和DS18B20的火灾温度-烟雾报警系统设计,51单片机,附仿真、C代码、原理图和PCB等
顺序栈的基本操作
基于TLC5615的多路可调数控直流稳压电源,51单片机,含Proteus仿真和C代码等
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
关于UDP接收icmp端口不可达(port unreachable)
asp.net使用MailMessage发送邮件的方法
XX project structure notes
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
随机推荐
Qt界面优化:Qt去边框与窗体圆角化
API Gateway/API 网关(三) - Kong的使用 - 限流rate limiting(redis)
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
TUN 设备原理
asp.net使用MailMessage发送邮件的方法
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
网页自适应,等比缩放
JS parabola motion packaging method
Introduction to the use of semaphore for inter thread control
关于UDP接收icmp端口不可达(port unreachable)
处理 mkdir:无法创建目录“aaa“:只读文件系统
一篇博客让你学会在vscode上编写markdown
redis 模块编程中 key value的生命周期
async void 导致程序崩溃
JumpServer
ie8 浏览器提示是否 阻止访问js脚本
剑指offer刷题(1)--面向华为
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
Solve the problem of SSH configuration file optimization and slow connection
js 进度条,显示加载进度