zoukankan      html  css  js  c++  java
  • Java知识系统回顾整理01基础04操作符05赋值操作符

    一、赋值操作

    赋值操作的操作顺序是从右到左 

    int i = 5+5; 

    首先进行5+5的运算,得到结果10,然后把10这个值,赋给i

    public class HelloWorld {

        public static void main(String[] args) {

            int i = 5+5;

        }

    }

       

    二、对本身进行运算,并赋值

    +=即自加

    i+=2;

    等同于

    i=i+2;

    其他的 -= , *= , /= , %= , &= , |= , ^= , >>= , >>>= 都是类似,不做赘述

    public class HelloWorld {

        public static void main(String[] args) {

            int i =3;

            i+=2;

            System.out.println(i);

              

            int j=3;

            j=j+2;

            System.out.println(j);    

       

        }

    }

       

    三、小练习

    题目:

    int i = 1;

    i+=++i;

    心算i的值是多少?

       

    官方答案:

    i+=++i;

    首选运算右边,运算结束后,i的值变为2,++i表达式的值,返回2.

    然后再运算 i+=2,在2的基础上+1,最后结果是3

    public class HelloWorld {

        public static void main(String[] args) {

            int i = 1;

            i+=++i;

            // 2

            // 3

            System.out.println(i);

        }

    }

     

  • 相关阅读:
    状压DP
    string
    hdu3068
    HDU Stealing Harry Potter's Precious(状压BFS)
    状压BFS
    BFS+打印路径
    poj Meteor Shower
    C语言-无符号数与有符号数不为人知的秘密
    keras_实现cnn_手写数字识别
    python_plot画图参数设置
  • 原文地址:https://www.cnblogs.com/xlfcjx/p/10770224.html
Copyright © 2011-2022 走看看