zoukankan      html  css  js  c++  java
  • JAVA学习(运算符2)

    package operator;
    //逻辑运算符 && (与)、||(或)、!(非)
    public class Demo05 {
        public static void main(String[] args) {
            boolean a = true;
            boolean b = false;
            System.out.println("a && b:"+(a&&b));
            System.out.println("a || b:"+(a||b));
            System.out.println("!(a && b):"+!(a&&b));
            //短路运算
            int c = 5;
            boolean d = (c<4)&&(c++<4);
            System.out.println(d);//false
            System.out.println(c);//5
        }
    }
    package operator;
    
    public class Demo06 {
        public static void main(String[] args) {
    
            System.out.println();
            /*
            A = 0011 1100
            B = 0000 1101
    
            A&B 0000 1100
            A/B 0011 1101
            A^B 0011 0001  相同取0,不同得1
            ~A  1100 0011  取反
    
            2*8 怎么运算最快?
            <<  *2
            >>  /2
             */
            System.out.println(2<<3);
        }
    }
    package operator;
    
    public class Demo07 {
        public static void main(String[] args) {
            int a = 10;
            int b = 20;
            a+=b; //a=a+b
            a-=b; //a=a-b
            System.out.println(a);//10
    
            //字符串连接符  +
            System.out.println(a+b); //30
            System.out.println(""+a+b); //1020 只要不在最末尾,都会把其余转化为String
            System.out.println(a+b+""); //30
        }
    }
    package operator;
    
    //三元运算符
    public class Demo8 {
        public static void main(String[] args) {
            // x?y:z
            //x ture 结果为y,否则结果为z
            int score = 80;
            String type = score < 60 ?"不及格":"及格"; //必须掌握
    
            System.out.println(type);
        }
    }
  • 相关阅读:
    异常处理
    面向对象 -- 内置方法
    面向对象 -- 反射(详细)
    面向对象 -- 反射
    面向对象 -- 三大特性之封装
    pickle模块 collections模块在面向对象中的应用
    面向对象 -- 三大特性之多态
    Third Week(补充完整)
    Second Week(补充完整)
    First Week (补充完整)
  • 原文地址:https://www.cnblogs.com/cjybarcode/p/13065299.html
Copyright © 2011-2022 走看看