zoukankan      html  css  js  c++  java
  • 运算符要点

    运算符要点

    字符串连接符要点

    public class Demo07 {
        public static void main(String[] args) {
            int a = 10;
            int b = 20;
    
            a+=b;   //  a = a+b;
                   //  a = a-b;
    
            System.out.println(a);  //30
    
            //字符串连接符    +   ,String 只要有一边是String类型,就都会转换为String类型
            System.out.println(a+b);    //50
            System.out.println(""+a+b); //3020
            System.out.println(a+b+""); //50
        }
    }
    

    位运算符左移右移

    /*
    A = 0011 1100
    B = 0000 1101
    
    ----------------------
    
    A&B  = 0000 1100
    A|B  = 0011 1101
    A^B  = 0011 0001
    ~B   = 1111 0010
    
    2*8 = 16 2*2*2*2
    
    计算机组成原理
    效率极高!!!
    <<  左移  *2
    >>  右移  /2
    
     */
    
    System.out.println(2<<3);   //16
    

    &&运算符

    &&运算符是短路运算

    自增自减幂运算

    public class Demo04 {
        public static void main(String[] args) {
            //++ -- 自增  自减  一元运算符
            int a = 3;
    
            int b = a++;
            //a++  a = a + 1    先执行完这行代码后,先给b赋值,再自增
    
            System.out.println(a);
    
            //a++   a = a + 1
            int c = ++a;    //  执行玩这行代码前,先自增,再给b赋值
    
            System.out.println(a);
            System.out.println(b);
            System.out.println(c);
    
            //幂运算   很多运算,我们会使用一些工具类来操作!
            double pow = Math.pow(3,2);
            System.out.println(pow);
    
    
        }
    

    三元运算符

    public class Demo08 {
        public static void main(String[] args) {
            // x ? y : z
            //如果x==true,则结果为y,否则结果为z
    
            int score = 80;
            String type = score < 60 ?"不及格":"及格"; //必须掌握
            // if
            System.out.println(type);
        }
    }
    
  • 相关阅读:
    Spinlock
    Leetcode: Summary Ranges
    Leetcode: Search a 2D Matrix
    Leetcode: Rotate Image
    Leetcode: Length of Last Word in python
    BBC-unit7 session1
    BBC-unit6 session5
    BBC-unit6 session4
    BBC英语-unit6 session3
    BBC英语-unit6 session2
  • 原文地址:https://www.cnblogs.com/helloxiaolu/p/13246112.html
Copyright © 2011-2022 走看看