public class Ope01 {
public static void main(String[] args) {
//二元运算符
//快捷复制:Ctrl + D:复制当前单元到下一行
int a = 10;
int b = 20;
int c = 30;
int d = 40;
int e = 41;
System.out.println(a+b); //print 30
System.out.println(a-b); //print -10
System.out.println(a*b); //print 200
System.out.println(a/b); //print 0
System.out.println(a/(double)b); //print 0.5
//==============================================
System.out.println(c > d); //false,大于
System.out.println(c < d); //true,小于
System.out.println(c == d ); //false,等于
System.out.println(c != d); //true,不等于
System.out.println(e % a); //1 ,取余/模运算
}
}
public class Ope02 {
public static void main(String[] args) {
long a = 112131413535L;
int b = 123;
short c = 10;
byte d = 8;
System.out.println(a+b+c+d); //print 112131413563 long类型 若多个相加,有一个类型为long,结果就为long类型
System.out.println(b+c+d); //print 141 int类型 若多个相加,没有long类型,结果就是int类型
System.out.println(c+d); //print 18 int类型 若多个相加,没有long类型,结果就是int类型
}
}
public class Ope03 {
public static void main(String[] args) {
//一元运算符: 自增:++ 自减:--
int a = 3;
int b = a++ ; //执行完这行代码后,先给b赋值,再自增 a++是执行后先赋值再自增
//a++相当于a=a+1,此处相当于隐藏了一行赋值代码
System.out.println(a); //4 为何是4,因为a++相当于a=a+1,所以输出前要运行a=a+1
//此处隐藏了一行代码 a=a+1 先自增,再给c赋值
int c = ++a ; //执行完这行代码前,先自增,再给c赋值 ++a是先执行前自增
System.out.println(a); //5
System.out.println(b); //3
System.out.println(c); //5
//自减用法与自增一致
//幂函数运算 Math.pow
double r = Math.pow(2,3); //Math工具,后续很多运算会用到,非常重要
System.out.println(r); //8.0 幂函数运算,2的3次方
}
}