当前位置:网站首页>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
边栏推荐
- WinForm allows the form form to switch between the front and active states
- Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
- 2022 团体程序设计天梯赛 模拟赛 L2-3 浪漫侧影 (25 分)
- MySQL query specifies that a row is sorted to the first row
- Section 2 map and structure in Chapter 6
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- 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
- Charles uses three ways to modify requests and responses
- MySQL索引详解【B+Tree索引、哈希索引、全文索引、覆盖索引】
猜你喜欢

JS - accuracy issues

MySql关键字GROUP_CONCAT,组合连接查询

. net 5 Web custom middleware implementation returns the default picture

Node configuration environment CMD does not take effect

2022 团体程序设计天梯赛 模拟赛 L2-1 盲盒包装流水线 (25 分)

7-1 introduction to finance

Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types

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

C set

Flink customizes the application of sink side sinkfunction
随机推荐
MySQL keyword group_ Concat, combined connection query
Using swagger in. Net5
QT dynamic translation of Chinese and English languages
Detailed explanation of socket programming send() and recv() functions
Eight elder brothers chronicle [4]
【微服务】(十)—— 统一网关Gateway
AWS from entry to actual combat: creating accounts
Code forces round # 784 (DIV. 4) solution (First AK CF (XD)
月薪10k-20k都无法回答的事务问题,你会吗?
C-11 problem h: treasure chest 2
C-10 program error correction (recursive function): number to character
Unity knowledge points (ugui 2)
ThreadLocal 测试多线程变量实例
Visual programming -- how to customize the mouse cursor
Super easy to use [general excel import function]
Section 2 map and structure in Chapter 6
. net webapi access authorization mechanism and process design (header token + redis)
7-1 introduction to finance
Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
Knowledge of software testing~