当前位置:网站首页>Select knowledge points of structure
Select knowledge points of structure
2022-07-06 05:06:00 【I have nothing to do and like to chase plays】
if Single choice structure
import java.util.Scanner;
public class IfDemo01 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println(" Please enter the content ");
String str= sc.nextLine();
//equals Determines whether the strings are equal
if(str.equals("hello")){
System.out.println(str);
}
System.out.println("END");
sc.close();
}
}
Please enter the content
hello
hello
END
if Double choice structure
1. grammar :
if( Boolean expression 1){
// If the expression 1 The value of is true Execute code
}elseif( Boolean expression 2){
// If the expression 2 The value of is true Execute code
}elseif( Boolean expression 3){
// If the expression 3 The value of is true Execute code
}else{
// If none of the above Boolean expressions are true Execute code
}
2. Case study
import java.util.Scanner;
public class IfDemo02 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int score=sc.nextInt();
if(score==100){
System.out.println(" Congratulations, full mark ");
}else if(score<100&&score>=90){
System.out.println("A level ");
}else if(score<90&&score>=80){
System.out.println("B level ");
}else if(score<80&&score>=70){
System.out.println("C level ");
}else if(score<70&&score>=60){
System.out.println("D level ");
}else if(score<60&&score>=0){
System.out.println(" fail, ");
}else{
System.out.println(" The results are illegal ");
}
}
3.if A statement can have at most one else sentence ,else Statements in else if After statement ,
if A statement can have several else if sentence , They have to be in else The statement before , Once one of them else if The statement is detected as true, Other else if as well as else Statement will skip execution .
Nested if structure :
1. grammar :
if( Boolean expression 1){ // If the Boolean expression 1 The value of is true Execute code if( Boolean expression 2){ // If the Boolean expression 2 The value of is true Execute code } }
switch Multiple choice structure
There is another way to implement the multi-choice structure switch case sentence .
switch case Statement to determine whether a variable is equal to a value in a series of values , Each value is called a branch
switch The variable type of the statement can be :
1.byte,short,int perhaps char.
2. from javase7 Start switch Support string Sting type .
3. meanwhile case Label must be a string constant or literal .
grammar :
switch(exoression){ case value: // sentence break;// Optional case value: // sentence break;// Optional // You can have any number of case sentence default:// Optional // sentence }
Case study :
public class SwitchDemo01 { public static void main(String[] args) { //case through char grade='F'; switch(grade){ case 'A': System.out.println(" good "); break; case 'B': System.out.println(" good "); break; case 'C': System.out.println(" pass "); break; case 'D': System.out.println(" Make persistent efforts "); break; case 'E': System.out.println(" Fail "); break; default: System.out.println(" Unknown level "); } } }
public class SwitchDemo02 { public static void main(String[] args) { String name=" Juen-Kai Wang "; switch(name){ case " Juen-Kai Wang ": System.out.println(" Wang Junkai is so handsome "); break; case " hanah ": System.out.println(" Wang Yuan is really handsome "); break; case " Jackson Yi ": System.out.println(" Yiyang Qianxi is really handsome. "); break; default: System.out.println("TFBOYS The root is MiaoHong , The development will be better and better "); } }}
边栏推荐
- Redis 排查大 key 的4種方法,優化必備
- pix2pix:使用条件对抗网络的图像到图像转换
- February 12 relativelayout
- Lepton 无损压缩原理及性能分析
- [buuctf.reverse] 159_ [watevrCTF 2019]Watshell
- [leetcode16] the sum of the nearest three numbers (double pointer)
- 组播和广播的知识点梳理
- Supreme Court, judgment standard of divorce cases
- Simple understanding of interpreters and compilers
- Flink kakfa data read and write to Hudi
猜你喜欢
Nacos - TC Construction of High available seata (02)
ORM aggregate query and native database operation
Basic knowledge and examples of binary tree
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
[leetcode16] the sum of the nearest three numbers (double pointer)
Vite configures the development environment and production environment
Postman assertion
yolov5 tensorrt加速
Postman Association
RTP gb28181 document testing tool
随机推荐
JS quick start (II)
GAMES202-WebGL中shader的編譯和連接(了解向)
Implementing fuzzy query with dataframe
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Excellent PM must experience these three levels of transformation!
Huawei equipment is configured with OSPF and BFD linkage
RT thread analysis log system RT_ Kprintf analysis
The kernel determines whether peripherals are attached to the I2C address
关于imx8mp的es8316的芯片调试
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
Postman关联
Flink kakfa data read and write to Hudi
February 12 relativelayout
Nacos TC setup of highly available Seata (02)
CUDA11.1在线安装
JS quick start (II)
Programmers' position in the Internet industry | daily anecdotes
Leetcode 186 Flip the word II in the string (2022.07.05)
Extension of graph theory