当前位置:网站首页>Basic operator
Basic operator
2022-06-25 23:23:00 【Seasonal white September】
Operator
Arithmetic operator :+,—,*,/,%,++,–
Assignment operator :=
Relational operator :>,<,<=,>=,==,!=instanceof
Logical operators :&&,||,!
An operator :&,|,^,~,>>,<<,>>>
Conditional operator : ?:
Extended assignment operators :+=,-=,*=,/=
package operator;
public class Demo01 {
public static void main(String[] args) {
// Binary operator
int a=10;
int b=20;
int c=25;
int d=25;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);
}
}
package operator;
public class Demo2 {
public static void main(String[] args) {
long a=1564315151313L;
int b=123;
short c=10;
byte d=8;
System.out.println(a+b+c+d);//long
System.out.println(b+c+d);//int
System.out.println(c+d);//int
// If there is Advanced data types Then convert to advanced type In the operation ; As in the formula Yes long It is long type ;
// Or there is double It is doule type
// otherwise Convert to the lowest int type
}
}
package operator;
public class Demo03 {
public static void main(String[] args) {
// Relational operators return results : correct , error Boolean value
int a=10;
int b=10;
int c=21;
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a==b);
System.out.println(a!=b);
// Remainder or Modular arithmetic
System.out.println(c%a);// c/a 21/10= 2......1
}
}
package operator;
public class Demo04 {
public static void main(String[] args) {
// ++ -- Self increasing , Self reduction Unary operator
int a=3; //a=3
int b=a++; //b=a=3 a=a+1 a=4
int c=++a; //c=a+1=5 a=a+1=5
System.out.println(a);//a=5
System.out.println(b);//b=3
System.out.println(c);//c=5
// Power operation 2^3 2*2*2 =8 A lot of operations , We will use some tool classes to operate Math class
double pow =Math.pow(2,3);
System.out.println(pow);
}
}
package operator;
public class Demo05 {
public static void main(String[] args) {
// And (and) or (or) Not ( Take the opposite )
boolean a=true;
boolean b=false;
System.out.println("a&&b:"+(b&&a));// Logic and computation : Both variables are true The result is true
System.out.println("a||b:"+(a||b));// Logic or operation : One of the two variables is true The result is true
System.out.println("!(a&&b):"+!(a&&b));// Logical non operation : Both variables are false The result is true
// Short-circuit operation b&&a when b It's already fake 了 , There's no need to Continue to calculate the following
int c=5;
boolean d=(c<4)&&(c++<4);
System.out.println(d);//false
System.out.println(c);//5
}
}
package operator;
public class Demo06 {
public static void main(String[] args) {
/* A=0011 1100 B=0000 1101 A&B:0000 1100 The corresponding bits are 1 Then for 1; Otherwise 0 A|B:0011 1101 The corresponding bits are 0 Then for 0; Otherwise 1 A^B:0011 0001 If the corresponding bits are the same, it is 0; Otherwise 1 ~B:1111 0010 Take the opposite */
//2*8=16 2*2*2*2 How to calculate the fastest An operation
//<< >> Move left Move right
System.out.println(2<<3);
/* 0000 0000 0 0000 0001 1 0000 0010 2 0000 0011 3 . . . 0000 1000 8 0001 0000 16 Move left times 2 Move right divided by two Very efficient */
}
}
Output connector use plus Express
package operator;
public class Demo07 {
public static void main(String[] args) {
int a=10;
int b=20;
a+=b;// a=a+b
a-=b;// a=a-b
// String connector + ,String The string appears before Take the formula as character string Connect
// if The string appears after Then the previous formula goes first operation No effect
System.out.println(""+a+b);
System.out.println(a+b+"");
}
}
Output results as follows :
1020
30
package operator;
public class Demo08 {
public static void main(String[] args) {
// x?y:z
//if x==true The result is y , Otherwise, the result is z
int score=80;
String type =score<60?" fail, ":" pass ";
System.out.println(type);
}
}
priority
Brackets Internal priority Use more parentheses
边栏推荐
- Flex & Bison 開始
- 哪些PHP开源作品值得关注
- Huawei cloud SRE deterministic operation and maintenance special issue (the first issue)
- What do l and R of earphone mean?
- Several optimization scenarios using like fuzzy retrieval in SQL
- Svn icon disappearing solution
- My C language learning process
- Common MySQL database functions and queries
- Paper notes: multi tag learning MSWl
- The new version of Tencent's "peace elite" is coming: add a new account security protection system, and upgrade the detection of in-game violations
猜你喜欢

民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系

ES6 learning -- let

电路模块分析练习5(电源)

Xampp重启后,MySQL服务就启动不了。

哪些PHP开源作品值得关注

What aspects should we start with in the feasibility analysis of dry goods?

ES6 -- formal parameter setting initial value, extension operator, iterator, and generating function

Es7/es9 -- new features and regularities

No absurd tea applet - rule change

STM32开发板+机智云AIoT+家庭监测控制系统
随机推荐
电路模块分析练习5(电源)
ES6学习-- LET
ADB common commands
ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数
ES6-- 模板字符串、对象的简化写法、箭头函数
2、一个向量乘它的转置,其几何意义是什么?
What is 5g? What can 5g do? What will 5g bring in the future?
C language (I)
元宇宙标准论坛成立
[opencv450 samples] inpaint restores the selected region in the image using the region neighborhood
Ue4 Ue5 combine le plug - in de reconnaissance vocale de bureau pour la reconnaissance vocale
ES6 const constants and array deconstruction
异或运算符简单逻辑运算 a^=b
Unity technical manual - particle foundation main module attributes - upper
As a programmer, how can we learn, grow and progress happily? (personal perception has nothing to do with technology)
[eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
Circuit module analysis exercise 6 (switch)
2. What is the geometric meaning of a vector multiplying its transpose?
Network security project questions of the first Henan vocational skills competition in 2022
【opencv450 samples】创建图像列表yaml