运算符

  1. 算术运算符 + - * / % ++ --

    package operator;
    
    public class Demo01 {
        public static void main(String[] args) {
            //二元运算符
            //ctrl + D  复制当前到下一行
            int a = 10;
            int b = 20;
            int c = 5;
            int d = 15;
            System.out.println(a+b);
            System.out.println(a-b);
            System.out.println(a*b);
            System.out.println(a/(double)b);//除法会有小数  需要进行强制转换
    
    
        }
    }
    
    
    package operator;
    
    public class Demo02 {
        public static void main(String[] args) {
            long a = 121231231231232L;
            int b = 123;
            short c = 10;
            byte d = 8;
    
            System.out.println(a+b+c+d);// 里面有long 就按long类型输出
            System.out.println(b+c+d);// 没有long  按int类型输出
            System.out.println(c+d);
        }
    }
    
    
    package operator;
    
    public class Demo04 {
        public static void main(String[] args) {
            //++  --  自增 自减  一元运算符
            int a = 3;
            int b = a++; // a++  a = a + 1   先给b赋值,再自增相当于在代码后一行   a = a + 1
            int c = ++a; // ++a  a = a + 1   先自增,再把值给c赋值  相当于再代码前一行 执行 a = a + 1
    
            System.out.println(a);
            System.out.println(b);
            System.out.println(c);
    
            // 幂运算  2^3  2×2×2  会使用工具类进行运算操作
            double pow = Math.pow(3, 2);
            System.out.println(pow);
    
        }
    }
    
    
  2. 赋值运算符 =

  3. 关系运算符 > < >= <= == != instanceof

    package operator;
    
    public class Demo03 {
        public static void main(String[] args) {
            //关系运算符返回值;布尔值
    
            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);// 取余数  模运算
        }
    }
    
    
  4. 逻辑运算符 && || !

  5. 位运算符号 & |