//二元运算符
int a = 10;
int b = 10;
int c = 10;
int d = 10;
System.out.println(a+b);
System.out.println(a-b);
System.out.println(a*b);
System.out.println(a/(double)b);
long a =123123123123L;
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
//关系运算符返回的结果: 正确,错误 布尔值
int a = 10;
int b = 20;
int c = 21;
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a==b);
System.out.println(a!=b);
System.out.println(c%a);
//++自增 --自减c
int a = 3;
int b = a++;//执行这段代码后,先给b赋值,再自增
//a++:a=a+1
System.out.println(a);
int c = ++a;//执行这段代码后,先自增,再给c赋
System.out.println(a);
System.out.println(b);
System.out.println(c);
//幂运算 很多运算可以使用工具类来运算
double pow = Math.pow(2,3);
System.out.println(pow);
package operator;
//逻辑运算符
public class Demo05 {
public static void main(String[] args) {
//与(and)或(or)非(取反)
boolean a = true;
boolean b = false;
System.out.println("a && b:" + (a&&b));//逻辑与运算:两个变量都为真,结果才为true
System.out.println("a || b:" + (a||b));//逻辑与运算:两个变量有一个为真,结果才为true
System.out.println("!(a && b)" + !(a&&b));//如果是真,则变为假,如果是假则变为真
//短路运算
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);
System.out.println(c);//c++没有执行,所以还是5
}
}
public class Demo07 {
public static void main(String[] args) {
int a = 10;
int b = 20;
a+=b;
a-=b;
System.out.println(a);
//字符串连接符 + ,String
System.out.println(""+a+b);//1020
System.out.println(a+b+"");//30
}
}
//三元运算符
public class Demo08 {
public static void main(String[] args) {
//x ? y : z
//如果x==true,则结果为y,否则结果为z
int score = 80;
String type = score <60 ?"不及格":"及格";
System.out.println(type);
}
}