运算符的使用
//二元运算符
//Ctrl + D : 复制当前行到下一行 一个很好用的快捷键
int a = 10;
int b = 20;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);
//需要转换一下否则会出错
System.out.println("=======================");
//计算结果自动转换
long c = 1234567891;
int d = 123;
short e = 10;
byte f = 2;
System.out.println(c+d+e+f);//long
System.out.println(d+e+f);//Int
System.out.println(e+f);//Int
//运算时有long或者double结果就是这两个类型
//否则就是Int
//工具类 Math
double pow = Math.pow(2,3);//计算2^3
System.out.println(pow);
System.out.println("=======================");
//逻辑运算符 与 或 非
boolean g = true;
boolean h = false;
System.out.println("g && h:"+(g&&h));
System.out.println("g || h:"+(g||h));
System.out.println("!(g && h):"+!(g&&h));
//短路运算
int i = 5;
boolean j = (i<4)&&(i++<4);//i<4结果为false i++不会运行
System.out.println(j);
System.out.println(i);//5
System.out.println("=======================");
//位运算
/*
a = 0011 0010
b = 0011 0101
-----------------------
a&b = 0011 0000
a|b = 0011 0111
a^b = 0000 0111
~b = 1100 1010
*/
/*
2*8 == 2<<3
<< *2
>> /2
*/
System.out.println(2<<3);//16
System.out.println("=======================");
//字符串连接符 +
System.out.println(""+10+20);//1020
System.out.println(10+20+""+30);//3030
//String在前则后面也会转化为String类型
//在后则会先运算 在String之后的都会按照String类型操作
三目运算符不陌生了这里简单举个例子
a>b? c:d
如果a>b为true 则结果为c,否则为d
标签:int,System,运算符,&&,println,out From: https://www.cnblogs.com/xmingx/p/18047345