当前位置:网站首页>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
边栏推荐
- 处理 mkdir:无法创建目录“aaa“:只读文件系统
- redis的五种数据类型
- Processing MKDIR: unable to create directory 'AAA': read only file system
- Man man notes and @ reboot usage of crontab
- 基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
- flannel 原理 之 子网划分
- 循环队列的基本操作,你学会了吗?
- Mysql的安装过程(已经安装成功的步骤说明)
- TLS/SSL 协议详解 (30) SSL中的RSA、DHE、ECDHE、ECDH流程与区别
- 关于在vs中使用scanf不安全的问题
猜你喜欢
KVM learning resources
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
流程控制之分支语句
剑指offer刷题(2)--面向华为
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
Notes on Visio drawing topology
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
ArrayList集合基本使用
统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
循环队列的基本操作,你学会了吗?
随机推荐
xx项目架构随记
Qt界面优化:鼠标双击特效
差分隐私(背景介绍)
Detailed explanation of SAR command
JumpServer
百度笔试2022.4.12+编程题目:简单整数问题
错误:无法远程查找到密钥 “428F7ECC7117F726“
Redis源码分析之PSYNC同步
DS1302的电子万年历_51单片机,年月日、星期、时分秒、农历和温度,带闹钟,全套资料
ArrayList集合基本使用
Tongxin UOS uninstall php7 2.24, install php7 4.27 ; Uninstall and then install PHP 7.2.34
交通灯系统51单片机设计(附Proteus仿真、C程序、原理图及PCB、论文等全套资料)
MySQL基础知识
x509证书cer格式转pem格式
KVM学习资源
Upgrade of openssh and modification of version number
字节面试编程题:最小的K个数
初识STL
Use the executors class to quickly create a thread pool
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】