当前位置:网站首页>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
边栏推荐
- Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics
- 2022 group programming ladder simulation match 1-8 are prime numbers (20 points)
- 场景题:A系统如何使用B系统的页面
- Test questions and some space wars
- Query stored procedures in PostgreSQL
- Codeforces round 784 (Div. 4) (AK CF (XD) for the first time)
- poi根据数据创建导出excel
- 2022 团体程序设计天梯赛 模拟赛 L2-3 浪漫侧影 (25 分)
- Section 1 array and slicing in Chapter 6
- Using swagger in. Net5
猜你喜欢
Iotos IOT middle platform is connected to the access control system of isecure center
Codeforces Round #784 (Div. 4)題解 (第一次AK cf (XD
L3-011 直捣黄龙 (30 分)
Visual programming - Experiment 1
Visual programming - Experiment 2
【微服务】(十)—— 统一网关Gateway
PYMOL-note
Super easy to use [general excel import function]
Redis(17) -- Redis缓存相关问题解决
L3-011 direct attack Huanglong (30 points)
随机推荐
Charles uses three ways to modify requests and responses
Database - MySQL -- Navicat import SQL error 1067 - invalid default value for 'paydate‘
Unity Basics
Punch in: 4.23 C language chapter - (1) first knowledge of C language - (12) structure
2022 group programming ladder simulation l2-1 blind box packaging line (25 points)
Visual programming - drawing assignment
Test questions (2)
socket編程 send()與 recv()函數詳解
js 中,为一个里面带有input 的label 绑定事件后在父元素绑定单机事件,事件执行两次,求解
poi根据数据创建导出excel
MySQL keyword group_ Concat, combined connection query
Code forces round # 784 (DIV. 4) solution (First AK CF (XD)
L3-011 direct attack Huanglong (30 points)
Basic use of Charles
. net 5 Web custom middleware implementation returns the default picture
C interface
集合之List接口
MySQL grouping query rules
Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
Learn about I / O flow and file operations