当前位置:网站首页>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 "); } }}
边栏推荐
- Postman前置脚本-全局变量和环境变量
- pix2pix:使用条件对抗网络的图像到图像转换
- 二叉树基本知识和例题
- [noip2009 popularization group] score line delimitation
- Ora-01779: the column corresponding to the non key value saving table cannot be modified
- Implementing fuzzy query with dataframe
- 【LGR-109】洛谷 5 月月赛 II & Windy Round 6
- Extension of graph theory
- Oracle deletes duplicate data, leaving only one
- Nestjs配置文件上传, 配置中间件以及管道的使用
猜你喜欢
CUDA11.1在线安装
Please wait while Jenkins is getting ready to work
JS quick start (II)
Golang -- TCP implements concurrency (server and client)
Postman assertion
Rce code and Command Execution Vulnerability
Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
Nacos - TC Construction of High available seata (02)
Fuzzy -- basic application method of AFL
程序员在互联网行业的地位 | 每日趣闻
随机推荐
Set detailed map + interview questions
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
[lgr-109] Luogu may race II & windy round 6
[NOIP2008 提高组] 笨小猴
Fuzzy -- basic application method of AFL
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
idea一键导包
2021robocom robot developer competition (Preliminary)
Nacos - TC Construction of High available seata (02)
Lepton 无损压缩原理及性能分析
你需要知道的 TCP 三次握手
[数学建模] 微分方程--捕鱼业的持续发展
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
Microblogging hot search stock selection strategy
Three.js学习-光照和阴影(了解向)
Fuzzy -- basic application method of AFL
Crazy God said redis notes
EditorUtility. The role and application of setdirty in untiy
Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
MPLS experiment