当前位置:网站首页>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
边栏推荐
- Chapter 8 of C language programming (fifth edition of Tan Haoqiang) is good at using pointer exercises to analyze and answer
- Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
- Téléchargement en vrac de fichiers - téléchargement après compression
- Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
- Problem a: face recognition
- Visual programming - Experiment 2
- When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
- 打卡:4.23 C语言篇 -(1)初识C语言 - (12)结构体
- Supersocket is Used in net5 - command
- String input problem
猜你喜欢

【微服务】(十)—— 统一网关Gateway

MySQL之explain关键字详解

Test questions and some space wars

A comprehensive understanding of static code analysis
![Super easy to use [general excel import function]](/img/9b/ef18d1b92848976b5a141af5f239b5.jpg)
Super easy to use [general excel import function]

. net 5 Web custom middleware implementation returns the default picture

Optimization of especially slow startup in idea debugging mode

How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing

Punch in: 4.22 C language chapter - (1) first knowledge of C language - (11) pointer

Charles uses three ways to modify requests and responses
随机推荐
数据库表中不建索引,在插入数据时,通过sql语句防止重复添加(转载)
Log4net is in Net core usage
js 中,为一个里面带有input 的label 绑定事件后在父元素绑定单机事件,事件执行两次,求解
MySql分组查询规则
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics
MySql关键字GROUP_CONCAT,组合连接查询
第四次作业
Learn about I / O flow and file operations
Database - MySQL -- Navicat import SQL error 1067 - invalid default value for 'paydate‘
Visual programming - Experiment 2
全新的ORM框架——BeetlSQL介绍
Student achievement management
2022 group programming ladder game simulation L2-4 Zhezhi game (25 points)
A comprehensive understanding of static code analysis
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
Using jsonserialize to realize data type conversion gracefully
How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
超好用的Excel异步导出功能
7-1 introduction to finance