package www.base;
/**
* 1,除法除不尽的情况下需要用double类型,int类型会导致运算精度丢失
* 2,long int short byte, 当这些类型运算时有long,则最后结果为long类型,否则都为int类型。
*/
/**
* 优先符 ()
* 算术运算符 + - * / %(取余) [++ --]:根据位置决定先赋值还是先自增或自减
* 赋值运算符 =
* 关系运算符 > < >= <= == != instanceof
* 逻辑运算符 &&-and ||-or !-not
* 位运算符 & | ^ ~ >> << >>>
* 条件运算符 ? :
* 扩展运算符 += -= *= /=
*/
public class Demo004_Operator {
public static void main(String[] args) {
//Ctrl+D 复制当前行到下一行
//二元运算
int a = 10;
int b = 20;
System.out.println(a/b);
System.out.println(a/(double)b);
System.out.println("=============================");
int a1 = 10;
int b1 = 20;
int c1 = 23;
System.out.println(c1%a1);
System.out.println(a1==b1);
System.out.println(c1>=b1);
System.out.println("=============================");
int a2 = 3;
int b2 = a2++; //先赋值,在自增
/**
* int b2 = a2
* a2 = a2 + 1
*/
System.out.println(b2);
int c2 = ++a2; //先自增,在赋值
/**
* a2 = a2 + 1
* c2 = a2
*/
System.out.println(c2);
System.out.println("=============================");
//幂运算
double pow = Math.pow(3,2);
System.out.println(pow);
System.out.println("===短路运算====================");
boolean t = true;
boolean f = false;
System.out.println("t&&f:"+(t&&f)); //两个都为真,结果为真
System.out.println("t||f:"+(t||f)); //有一个为真,结果为真
System.out.println("!(t&&f):"+!(t&&f)); //如果为真,结果为假;如果为假,结果为真。
/**
* 短路运算, 在逻辑运算中,如果第一个已经可以判断结果,则后面的不会在计算
*/
int c3 = 5;
boolean d3 = (c3<4)&&(c3++<4);
System.out.println(d3);
System.out.println(c3);
}
}