当前位置:网站首页>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
边栏推荐
- App new function launch
- Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
- 提问的智慧?如何提问?
- Determine whether the appointment time has expired
- PDM fur
- pdm导入vscode的实现方式
- Exclusive or operator simple logic operation a^=b
- Somme logarithmique (deux points) pour le Groupe 52 - - e de la course de la lune blanche de niuke
- 不荒唐的茶小程序-规则改动
- Unity technical manual - particle foundation main module attributes - upper
猜你喜欢
Circuit module analysis exercise 5 (power supply)
不荒唐的茶小程序-规则改动
电路模块分析练习5(电源)
【EOSIO】EOS/WAX签名错误 is_canonical( c ): signature is not canonical 问题
百度:2022年十大热度攀升专业出炉,第一名无悬念!
民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
ES6-Const常量与数组解构
STM32 development board + smart cloud aiot+ home monitoring and control system
Meta universe standard forum established
[eosio] eos/wax signature error is_ Canonical (c): signature is not canonical
随机推荐
干货丨产品的可行性分析要从哪几个方面入手?
Circuit module analysis exercise 5 (power supply)
问题记录与思考
关闭MongoDB一些服务需要注意的地方(以及开启的相关命令)
What do l and R of earphone mean?
电路模块分析练习6(开关)
哪些PHP开源作品值得关注
My C language learning process
Comp212 distributed protocol
Implementation of importing vscode from PDM
C language and the creation and use of database
Unity technical manual - color in life cycle coloroverlifetime-- speed color colorbyspeed
What is CDN acceleration
The wisdom of questioning? How to ask questions?
MySQL数据库常用函数和查询
Unity的Ping類使用
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
Somme logarithmique (deux points) pour le Groupe 52 - - e de la course de la lune blanche de niuke
Transformers load pre training model
pdm的皮毛