java 运算符

  • 算术运算符:+,-,*,/,%,++,--

  • package com.yan.Operator;
    
    public class Dome001 {
        public static void main(String[] args) {
            //两位数的运算叫做二元运算符
            //Ctel+d 复制到下一行
    
            int a = 10 ;
            int a1 = 20 ;
            int a2 = 25 ;
            int a3 = 20 ;
    
            System.out.print(a+a1);
            System.out.print(a-a2);
            System.out.print(a*a3);
            System.out.print(a/(double)a3);
    
    
            //不同类型计算,向计算单位中最高位转换
            byte byte1 = 8;
            short short1 = 176;
            int int1 = 21005;
            long long1 = 121561;
            double double1 = 3.1415;
            System.out.print(byte1+short1+int1+long1+double1);
            System.out.print(byte1+short1+int1+long1);
            System.out.print(byte1+short1+int1);
            System.out.print(byte1+short1);
            System.out.print(byte1>=short1);
            System.out.print(byte1<=short1);
            System.out.print(byte1==short1);
    
        }
    }
    
  • 赋值运算符:= a=10;(把10赋值给a这个变量)

  • 关系运算符:<,>,>=,<=,==,=!, instanceof

  • 逻辑运算符:&&(什么与什么),||(什么或什么),!(不等,非)

  • package com.yan.Operator;
    
    public class Dome003 {
        public static void main(String[] args) {
            boolean a = true;
            boolean b = false;
            //&&:与    真假 为 假 。 真真为真
             System.out.print("a&&b:"+(a&&b));
             //||:或(并集) 真假 为真 。
             System.out.print("a||b:"+(a||b));
             //!:非(与&&相反的) true && true 为真。  !(true && true) 为假
             System.out.print("!(a&&b)"+!(a&&b));
    
             //短路运算
            int c = 1 ;
            boolean d = ((c>4)&&(c++<3));
            System.out.print(c);
            System.out.print(d);
        }
    }
  • 位运算符:&,|,^,~,>>,<<,>>>

  • 条件运算符:?

  • package com.yan.Operator;
    
    public class Dome005 {
        public static void main(String[] args) {
            //三目运算符
            //x?y:z 如果x = true,则为y,否则为z
    
            int score = 59;
            String type = score<60?"不及格":"及格";
            System.out.print(type);
    
            int result  = 1 ;
            String type1 = result  != 1 ?"工资2500":"回家养猪";
            System.out.print(type1);
    
    
        }
    }

  • 扩展赋值运算符:+=,-=,*=,/=

    package com.yan.Operator;
    
    public class Dome002 {
        //自增++  a++(先用后增) ++a(先增后用)
        public static void main(String[] args) {
            int a = 1;
            int b = a++;
            System.out.print(b);
    
            int c = ++a;
    
            System.out.print(a);
            //System.out.print(b);
            System.out.print(c);
    
            //幂运算
            double d = Math.pow(2,3);
            System.out.print(d);
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值