栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java 运算符

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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);
        }
    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/351643.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号