• 欢迎光临~

# 基本运算符

package com.beijing.xiaowen.operator;

public class Demo01 {
public static void main(String[] args) {
int a = 10;
int a1 = 20;
int a2 = 30;
int a3 = 40;

System.out.println(a * a1);
System.out.println(a / a1);//0
System.out.println(a / (double)a1);//0.5 有小数的时候，记得用浮点型
System.out.println(a2 + a1);
System.out.println(a3 - a1);

long z = 8979879L;
short x = 33;
byte c = 2;
int v = 10;
System.out.println(z+x+c+v);//结果为long
System.out.println(x+c+v);//结果为int
System.out.println(x+c);
}
}

# 自增自减运算符

package com.beijing.xiaowen.operator;

public class Demo02 {
public static void main(String[] args) {
int a = 1;
int b = a++;//执行完这行代码后，先给b赋值，再自增
System.out.println(b);//1
int c = ++a;//执行完这行代码前，先自增，再给c赋值
System.out.println(c);//3
}
}

# 初识math类

//幂运算
double pow = Math.pow(3, 2);
System.out.println(pow);//9

# 位运算符

package com.beijing.xiaowen.operator;

public class Demo03 {
public static void main(String[] args) {
//  & | ^ ~ << >>

/**
*  A = 0011 1100
*  B = 0000 1101
*  A&B = 0000 1100
*  A|B = 0011 1101
*  A^B = 0011 0001
*  ~B  = 1111 001199
*
*  2*8  2*2*2*2
*
*  << *2
*  >> /2
* */
System.out.println(2<<3);//16
}
}

# 字符串连接符

package com.beijing.xiaowen.operator;

public class Demo04 {
public static void main(String[] args) {
int a = 10;
int b = 10;
System.out.println(a+=b);//a=a+b
System.out.println(a-=b);//a=a-b

//字符串拼接符
System.out.println(""+a+b);//1010
System.out.println(a+b+"");//30
}
}

# 三元运算符

package com.beijing.xiaowen.operator;

public class Demo05 {
public static void main(String[] args) {
//? :
//x ? y : z   x为true则为y，否则为z
int a = 66;
System.out.println(a>88?"啊哈":"嗯哼");
}
}