当前位置:网站首页>Operator explanation
Operator explanation
2022-07-05 00:26:00 【The learning path of Java Rookies】
Operator
One 、 Arithmetic operator
1、 Definition
Arithmetic operators operate on numeric variables
2、 Introduction to arithmetic operators

3、 modulus % The essence of
% It's used to take the remainder , Can only be used in integers
modulus a%b The essence is :
a % b = a - a / b * b
10 % 3 => - 10 - (- 10) / 3 * 3 = - 10 + 9 = - 1
10 % -3 = 10 - 10 / (-3) * (-3) = 10 - 9 = 1
10 % -3 = (- 10) - (- 10) / (-3) * (-3) = - 10 + 9 = - 1
4. Self increasing ++
front ++: First self increment and then assignment
after ++: Assign value first, then add value
int j = 8;
int k = ++j; // Equivalent j=j+1;k=j;
int k = j++; // Equivalent k =j;j=j+1;

Two 、 Relational operator
1、 Definition
- The result of relational operators is boolean type , That is, either true , Or false
- Relationship expression Often used in if In the condition of a structure or in the condition of a cyclic structure
2、 Introduction to relational operators

3、 Details
- The result of relational operators is boolean type , That is, either true , Or false.
- The expression made up of relational operators , We call it relational expression . a > b
- Comparison operator "==“ It can't be written by mistake ”="
3、 ... and 、 Logical operators
1、 Definition
Used to connect multiple conditions ( Multiple relational expressions ) , The end result is also a boolean value .
2、 Introduction to logical operators
- Short circuit and && , Short circuit or || , Take the opposite !
- Logic and & , Logic or | ,^ Logical XOR

3、 Operational rules
1) a&b : & It's called logic and : The rules : When a and b Also for true , The result is true, Otherwise false
2) a&&b : && It's called short circuit and : The rules : When a and b Also for true , The result is true, Otherwise false
3) a|b : | It's called logic or , The rules : When a and b , There is one for true , The result is true, Otherwise false
4) a||b : || It's called short circuit or , The rules : When a and b , There is one for true , The result is true, Otherwise false
5) !a : Call negative , Or non arithmetic . When a by true, The result is false, When a by false yes , The result is true
6) a^b: It's called logical XOR , When a and b Different time , The result is true, Otherwise false
about && Short circuit and , If the first condition is false , The latter condition is no longer to judge
about & Logically and logically , If the first condition is false , The latter conditions will still judge
Short circuit or : If the first condition is true,
Then the second condition will not judge , The final result is true , Efficient
Logic or : Whether or not the first condition is true , The second condition is to judge , Low efficiency
Four 、 Assignment operator
1、 Definition
An assignment operator is the value of an operation , Assign to the specified variable .
2、 Introduction to assignment operators
Basic assignment operators = int a = 10;
Compound assignment operator
+= ,-= ,*= , /= ,%= etc. ,
a += b; [ Equivalent a = a + b; ]
a -= b; [ Equivalent a = a - b; ]
3、 Characteristics of assignment operators
- The order of operation is from right to left int num = a + b + c;
- To the left of the assignment operator It can only be a variable , On the right It could be a variable 、 expression 、 Constant values int num = 20; int num2= 78 * 34 - 10; int num3 = a;
- The compound assignment operator is equivalent to the following effect such as : a+=3; Equivalent to a=a+3; Other analogies
- The compound assignment operator performs type conversion . byte b = 2; b+=3; b++;
byte b = 3;
b += 2; Equivalent b = (byte)(b + 2);
b++; b = (byte)(b+1);
5、 ... and 、 Ternary operator
1. Basic grammar
Conditional expression ? expression 1: expression 2;
Operational rules :
- If the conditional expression is true , The result of the operation is an expression 1;
- If the conditional expression is false , The result of the operation is an expression 2;
2. Use details
- expression 1 And expressions 2 Type that can be assigned to the receiving variable ( Or it can be automatically converted )
- The ternary operator can be converted to if–else sentence
int res = a > b ? a++ : --b;
if ( a > b) res = a++;
else res = --b;
// Ternary operator details
public class TernaryOperatorDetail {
// Write a main Method
public static void main(String[] args) {
// expression 1 And expressions 2 Type that can be assigned to the receiving variable
//( Or it can be automatically converted / Or cast )
int a = 3;
int b = 8;
int c = a > b ? (int)1. 1 : (int)3.4;// Tolerable
double d = a > b ? a : b + 3;// Tolerable , Satisfy int -> double
}
}
边栏推荐
- 两个数相互替换
- Using the uniapp rich text editor
- 企业应用业务场景,功能添加和修改C#源码
- IELTS examination process, what to pay attention to and how to review?
- 如何避免电弧产生?—— AAFD故障电弧探测器为您解决
- Cross domain request
- Skills in analyzing the trend chart of London Silver
- IT转测试岗,从迷茫到坚定我究竟付出了什么?
- 电力运维云平台:开启电力系统“无人值班、少人值守”新模式
- 【路径规划】RRT增加动力模型进行轨迹规划
猜你喜欢

abc 258 G - Triangle(bitset)

Netcore3.1 JSON web token Middleware

How to avoid arc generation—— Aafd fault arc detector solves the problem for you

Microservice

How to do the project of computer remote company in foreign Internet?

Hisilicon 3559 universal platform construction: YUV422 pit stepping record

Face recognition 5- insight face padding code practice notes
![[paper reading] Tun det: a novel network for meridian ultra sound nodule detection](/img/25/e2366cabf00e55664d16455a6049e0.png)
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection

Fs8b711s14 electric wine bottle opener MCU IC scheme development special integrated IC

雅思考试流程、需要具体注意些什么、怎么复习?
随机推荐
【北京大学】Tensorflow2.0-1-开篇
Distributed base theory
Netcore3.1 JSON web token Middleware
2022.07.03 (LC 6109 number of people who know secrets)
[monitoring] ZABBIX
2022.07.03(LC_6108_解密消息)
GDB常用命令
JS convert pseudo array to array
Power operation and maintenance cloud platform: open the new mode of "unattended and few people on duty" of power system
(script) one click deployment of any version of redis - the way to build a dream
兩個數相互替換
Consolidated expression C case simple variable operation
Réseau graphique: Qu'est - ce que le Protocole d'équilibrage de charge de passerelle glbp?
实战模拟│JWT 登录认证
【报错】 “TypeError: Cannot read properties of undefined (reading ‘split‘)“
How to save your code works quickly to better protect your labor achievements
uniapp上传头像
TS快速入门-函数
go踩坑——no required module provides package : go.mod file not found in current directory or any parent
图解网络:什么是网关负载均衡协议GLBP?