运算符
/**
* @param args
* 运算符
* 基本算术运算符:+ - * / &
* 赋值运算符:=(赋值) (恒等于) !=(不等于)
* += -= *= /= &=
* 比较运算符;(恒等) != >= <= > <
* 逻辑运算符;&&(与):只有所有值都为真才为真,否则都为假.
* ||(或):只要有一个值为真,就都为真.
* 条件运算符
*
* 丢失精度
*/
public static void main(String[] args) {
// TODO 自动生成的方法存根
//基本算术运算
int x = 100; //创建变量并赋值
int y = 67;
int sum; //创建了一个变量
sum = x + y;
System.out.println(sum);
sum = y * x;
System.out.println(sum);
sum = x / y;
System.out.println(sum);
sum = x & y;
System.out.println(sum);
//赋值运算
boolean flags;
flags = (x==y);
System.out.println(flags);
//自增
int s = x++; //先赋值,再自增
System.out.println(x);
System.out.println(s);
int s1 = ++x; //先自增,再赋值
System.out.println(x);
System.out.println(s1);
//自减
int s2 = x--; //先赋值,再自减
System.out.println(x);
System.out.println(s2);
int s3 = --x; //先自减,再赋值
System.out.println(x);
System.out.println(s3);
//赋值运算符
int a = 10;
int b = 260;
b += a; //b = b + a;
System.out.println(a);
System.out.println(b);
b -= a;
System.out.println(a);
System.out.println(b);
b *= a;
System.out.println(a);
System.out.println(b);
b /= a;
System.out.println(a);
System.out.println(b);
b &= a;
System.out.println(a);
System.out.println(b);
//比较运算符
int v = 90,c = 70;
boolean f;
f = (v==c);
System.out.println(f);
f = (v>c);
System.out.println(f);
f = (v>=c);
System.out.println(f);
System.out.println("----------------------------");
//逻辑运算符
boolean q = true, w = false;
System.out.println(q && q); // true && true
System.out.println(q && w); // true && false
System.out.println(w && q); // false && true
System.out.println(w && w); // false && false
System.out.println(q || q); // true && true
System.out.println(q || w); // true && false
System.out.println(w || q); // false && true
System.out.println(w || w); // false && false
}
}