当前位置:网站首页>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
}
}
边栏推荐
- C语言中sizeof操作符的坑
- (script) one click deployment of any version of redis - the way to build a dream
- Detailed explanation of openharmony resource management
- TS quick start - functions
- uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)
- Fast parsing intranet penetration helps enterprises quickly achieve collaborative office
- [论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
- 如果炒股开华泰证券的户,在网上开户安全吗?
- [monitoring] ZABBIX
- Hologres Query管理及超时处理
猜你喜欢

Huawei employs data management experts with an annual salary of 2million! The 100 billion market behind it deserves attention

Summer challenge brings you to play harmoniyos multi terminal piano performance

Tester's algorithm interview question - find mode

uniapp微信小程序拿来即用的瀑布流布局demo2(方法二)(复制粘贴即可使用,无需做其他处理)

In June, the list of winners of "Moli original author program" was announced! Invite you to talk about the domestic database
Date time type and format in MySQL

How to effectively monitor the DC column head cabinet

The waterfall flow layout demo2 (method 2) used by the uniapp wechat applet (copy and paste can be used without other processing)

Application of fire fighting system based on 3D GIS platform
![[IELTS reading] Wang Xiwei reading P4 (matching1)](/img/91/1b3f85410035f65acb0c205185f698.png)
[IELTS reading] Wang Xiwei reading P4 (matching1)
随机推荐
C语言中sizeof操作符的坑
挖财学院开户安全的吗?开户怎么开?
[paper reading] Tun det: a novel network for meridian ultra sound nodule detection
2022.07.03 (LC 6109 number of people who know secrets)
Application of fire fighting system based on 3D GIS platform
ORB(Oriented FAST and Rotated BRIEF)
初识ROS
It's too convenient. You can complete the code release and approval by nailing it!
Enterprise application business scenarios, function addition and modification of C source code
Hologres query management and timeout processing
Using the uniapp rich text editor
青海省国家湿地公园功能区划数数据、全国湿地沼泽分布数据、全国省市县自然保护区
巩固表达式C# 案例简单变量运算
Two numbers replace each other
P3304 [sdoi2013] diameter (diameter of tree)
Learning of basic amplification circuit
Continuous modification of business scenario functions
Is it safe to open an account in the College of Finance and economics? How to open an account?
[论文阅读] TUN-Det: A Novel Network for Thyroid Ultrasound Nodule Detection
Five papers recommended for the new development of convolutional neural network in deep learning