Java基础语法篇-demo07

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

public class demo07 {
    
    
    /**
     * 运算符
     * 算数运算符:+,-,*,/,%,++,--
     * 赋值运算符:=
     * 关系运算符:>,<,>=,<=,!=,instanceof
     * 逻辑运算符:&&,||,!
     * 位运算符:&,|,^,~,>>,<<,>>>,
     * 条件运算符:?
     * 扩展赋值运算符:+=,-=,*=,/=
     */

    public static void main(String[] args) {
    
    
        //二次运算符
        int a=10;
        int b=20;
        int c=30;
        int d=30;
        System.out.println(a+b);//30
        System.out.println(a-b);//-10
        System.out.println(a*b);//200
        System.out.println(a/(double)b);//0.5
        System.out.println("===============================");
        //关系运算符
        System.out.println(a>b);//false
        System.out.println(a==b);//false
        System.out.println(a!=b);//true
        System.out.println("===============================");
        //取余,模运算
        int e=3;
        System.out.println(a%e);//1
        System.out.println("===============================");
        //一次运算符 ++ --
        int t1=3;
        int t2=t1++;
        int t3=++t1;
        int t4=t1--;
        int t5=--t1;

        System.out.println(t1);//3
        System.out.println(t2);//执行完这行代码,先给t2赋值,后t1自增1
        System.out.println(t3);//执行完这行代码,先自增1,后赋值给t3
        System.out.println(t4);//5
        System.out.println(t5);//3
        System.out.println("===============================");
        //幂运算
        double pow=Math.pow(2,3);
        System.out.println(pow);
        System.out.println("===============================");
        //逻辑运算符     与(&&) 或(||) 非(!)
        boolean b1=true;
        boolean b2=false;
        System.out.println("b1&&b2 :"+(b1&&b2));//b1&&b2 :false
        System.out.println("b1||b2 :"+(b1||b2));//b1||b2 :true
        System.out.println("!b1 :"+!b1);//!b1 :false
        System.out.println("===============================");
        //短路运算
        int i1=3;
        boolean i2=(i1>4)&&(i1++>3);
        System.out.println(i2);//false
        System.out.println(i1);//3
        boolean i3=(i1>2)&&(i1++>3);
        System.out.println(i3);//false
        System.out.println(i1);//true
    }
}

猜你喜欢

转载自blog.csdn.net/QianXunZhe23/article/details/115220718
今日推荐