大数据系列-day3运算符

  • 算术运算符
class AriTest{
    public static void main(String[] args){
        int num1 = 12;
        int num2 = 5;
        
        int result1 = num1 / num2;
        // System.out.println(result1);
        
        int result2 = num1 / num2 * num2;
        // System.out.println(result2);
        
        double result4 = num1 / num2 + 0.0;
        double result5 = num1 / (num2 + 0.0);
        double result6 = (double)num1 / num2;
        double result7 = num1 / (double)num2;
        double result8 = (double)(num1 / num2);
        /*System.out.println(result4);
        System.out.println(result5);
        System.out.println(result6);
        System.out.println(result7);
        System.out.println(result8);*/
        
        // quyu
        int m1 = 12;
        int n1 = 5;
        // System.out.println("m1 % n1 = " + m1 % n1);
        
        int m2 = -12;
        int n2 = 5;
        // System.out.println("m2 % n2 = " + m2 % n2);
        
        int m3 = 12;
        int n3 = -5;
        // System.out.println("m3 % n3 = " + m3 % n3);
        
        int m4 = -12;
        int n4 = -5;
        // System.out.println("m4 % n4 = " + m4 % n4);
        // ++
        
        int a1 = 10;
        int b1 = ++a1;
        System.out.println("a1 = " + a1 + ", b1 = " + b1);
        
        int a2 = 10;
        int b2 = a2++;
        System.out.println("a2 = " + a2 + ", b2 = " + b2);
        
        int a3 = 10;
        ++a3;
        int b3 = a3;
        System.out.println(b3);
        
        short s1 = 10;
        s1++;
    }
}
  • 赋值符号
class SetValueTest{
    public static void main(String[] args){
        int i1 = 10;
        int j1 = 10;
        
        int i2, j2;
        i2 = j2 = 10;
        
        int i3 = 10, j3 = 10;
        
        //*****************************
        int num1 = 10;
        num1 += 2;
        System.out.println(num1);
        
        int num2 = 12;
        num2 %= 5;
        System.out.println(num2);
        
        short s1 = 10;
        s1 += 2;
        System.out.println(s1);
    }
}
  • 比较运算符
class CompareTest{
    public static void main(String[] args){
        int i = 10, j = 20;
        System.out.println(i == j);
        System.out.println(i=j);
    }
}
  •  逻辑运算符
public static void main(String[] args) {
    boolean b1 = true;
    b1 = false;
    int num1 = 10;
    if(b1 & (num1++ > 10)) {
        System.out.println("我现在在北京");
    }else {
        System.out.println("我现在在南京");
    }
        
    System.out.println("num1 = " + num1);


    boolean b2 = true;
    b2 = false;
    int num2 = 10;
    if(b2 && (num2++ < 0)) {
        System.out.println("我现在在北京");
    }else {
        System.out.println("我现在在南京");
    }
        
    System.out.println("num2 = " + num2);

    boolean b3 = false;
    b3 = true;
    int num3 = 10;
    if(b3 || (num3++ < 0)) {
        System.out.println("我现在在北京");
    }else {
        System.out.println("我现在在南京");
    }
        
    System.out.println("num3 = " + num3);
}
  • 三元运算符
public class SanYuanTest1 {
    public static void main(String[] args) {
        int m =12;
        int n = 5;
        
        int max = (m > n)? m: n;
        System.out.println(max);
        
        String maxStr = (m > n)? "m大" : "n大";
        System.out.println(maxStr);
    }
    
}

 

posted @ 2020-05-25 12:52  覆水难收d  阅读(122)  评论(0编辑  收藏  举报