package two;
public class Demo01 {
public static void main(String[] args) {
//运算符
//二元运算符
int a=10;
int b=20;
int c=30;
int d=40;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);
System.out.println(c%d);//求余
System.out.println("========================");
long e=37163812616381263L;
int f=2313;
short g=222;
byte h=120;
System.out.println(e+f+g+h);//37163812616383918;long型
System.out.println(f+g+h);//2655;int型
System.out.println(g+h);//342;int型
System.out.println("========================");
//关系运算,布尔运算,false,ture
System.out.println(a<b);
System.out.println(a>b);
System.out.println(a==b);
System.out.println(a!=b);
System.out.println("========================");
//++ -- 自增1 自减1 一元运算符
System.out.println(a++);//先输出,再自加1
System.out.println(++a);//先自加1,再输出
System.out.println(--a);//先自减1,再输出
System.out.println(a--);//先输出,再自减1
System.out.println("========================");
//逻辑运算符
//与(and)-->&& 或(or)-->|| 非 (取反)-->!
boolean aa=true;//真
boolean bb=false;//假
System.out.println("aa&&bb="+(aa&&bb));//两个为真,才为真。
System.out.println("aa||bb="+(aa||bb));//两个为假,才为假。
System.out.println("(aa&&bb)取反="+!(aa&&bb));
//短路运算-->
boolean cc=(c<20)&&(c++>20);
System.out.println(cc);
System.out.println(c);
System.out.println("=================");
a+=b;//a=b+a
a-=b;//a=b-a
System.out.println(a);
//字符连接符 + ,String
System.out.println(""+a+b);
System.out.println(a+b+"");
System.out.println("===============");
//三元运算符
//x? y:z
//如果x==true ,则结果y;否则z
String type=a>20?"对了":"错了";//if
System.out.println(type);
}
}
位运算符部分的重要点
package two;
public class Demo02 {
/*
A=0011 0011
B=0010 1010
---------------------
A&B=0010 0010
A|B=0011 1011
A^B=0001 1001
~B=1101 0101
---------------------
2*8=16 2*2*2*2
效率极高
<< *2
>> /2
(重要)
-----------------------
0000 0000 0
0000 0001 1
0000 0010 2
0000 0100 4
0000 1000 8
0001 0000 16
*/
public static void main(String[] args) {
System.out.println(2<<3);//16
}
}
C:\Users\
30
-10
200
0.5
30
========================
37163812616383918
2655
342
========================
true
false
false
true
========================
10
12
11
11
========================
aa&&bb=false
aa||bb=true
(aa&&bb)取反=true
false
30
=================
10
1020
30
===============
错了
Process finished with exit code 0
注意看注解