当前位置:网站首页>If statement format flow
If statement format flow
2022-04-23 03:28:00 【Aiyou coffee】
if The sentence format is
if( Relationship expression ){
Statement of body ;
}
Execute the process :
1. First calculate the value of the relational expression
2. If the value of the relationship expression is true Execute the body of the statement
3. If the value of the relationship expression is false Do not execute the statement body
4. Continue to execute the following statements
public class IfDemo{
public class void main (String []args){
// Defining variables
int a =2;
int b = 4;
if(a==b){
System.out.println("a be equal to b");
}
System.out.println(" It's not equal to ");
}
}
If so a=b Then it will be output "a be equal to b", If ah !=b Then it will output " It's not equal to ".
This format is written to feel good , But one drawback is that only one condition can be set , If there is a second condition, it can no longer be realized . So there will be if sentence .
if.......else
Format :
if( Relationship expression ){
Statement of body 1
}else{
sentence 2
}
Execute the process :
- First calculate the value of the relational expression
- If the value of the relationship expression meets the first condition , Then execute the statement body 1
- If the value of the relational expression does not meet the first condition and meets the second condition , Then execute the statement body 2
- Continue to execute the following statements
public class IfDemo{
public static void main(String []args){
// Define two variables
int a = 3;
int b = 6;
if(a>b){
System.out.println("a Greater than b")
}else{
System.out.println("a The value is less than b")
}
}
}
This code has two different conditions , If you meet the first one, go the first one , Then the second one won't be executed again .
In line with the second, it will go directly into the second instead of going into the first and coming out again .
use if Sentence to solve
Segmentation of scores
public class IfDemo{
public static void main (String []args){
int score =(int)(100*Math.random());
System.out.println(" The score is "+score+" Belong to ");
if (score>=90){
System.out.println(" Great ");
}else if (score>=80){
System.out.println(" just so so ");
}else if(score>=60){
System.out.println(" Just passed. ");
}else{
System.out.println(" I didn't do well in the exam ");
}
}
}
版权声明
本文为[Aiyou coffee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220619009109.html
边栏推荐
- 2022 group programming ladder simulation l2-1 blind box packaging line (25 points)
- AWS from entry to actual combat: creating accounts
- 场景题:A系统如何使用B系统的页面
- Docker拉取mysql并连接
- Idempotency practice operation, explaining idempotency based on business
- Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
- 关于idea调试模式下启动特别慢的优化
- Redis(17) -- Redis缓存相关问题解决
- JS recursive tree structure calculates the number of leaf nodes of each node and outputs it
- Generate QR code through zxing
猜你喜欢

C abstract class

Unity basics 2

Experiment 6 input / output stream

Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer

2022 group programming ladder simulation match 1-8 are prime numbers (20 points)

Huawei mobile ADB devices connection device is empty

2022 group programming ladder game simulation L2-4 Zhezhi game (25 points)

Seminar playback video: how to improve Jenkins' ability to become a real Devops platform

MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
![Idea view history [file history and project history]](/img/b2/3128105eca7449c55146ce3b9e5c2e.png)
Idea view history [file history and project history]
随机推荐
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
L3-011 直捣黄龙 (30 分)
Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics
Quartz. Www. 18fu Used in net core
Explication détaillée des fonctions send () et recv () du programme Socket
Experiment 6 input / output stream
【微服务】(十)—— 统一网关Gateway
L3-011 direct attack Huanglong (30 points)
MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
Five tips for cross-border e-commerce in 2022
Explanation keyword of MySQL
"Visual programming" test paper
JS, bind the event for a label with input, and then bind the stand-alone event in the parent element. The event is executed twice and solved
ThreadLocal test multithreaded variable instance
POI create and export Excel based on data
The content of the website is prohibited from copying, pasting and saving as JS code
Super easy to use asynchronous export function of Excel
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
C interface
Node configuration environment CMD does not take effect