集册 Java实例教程 如何使用Java增量运算符(++)和减量(

如何使用Java增量运算符(++)和减量(

欢马劈雪     最近更新时间:2020-01-02 10:19:05

671
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java增量运算符++将其操作数的值增加一,而减量运算符-将其操作数的值减少一。

 

public class Main {/** from 时   代    Java - nowjava.com**/

 

        public static void main(String[] args) {

                 int i = 10;

                 int j = 10;

                 

                 i++;

                 j++;

                 

                 System.out.println("i = " + i);

                 System.out.println("j = " + j);

                 

                  /*

                   * value of i would be assigned to k and then its

                   * incremented by one.

                   */

                  int k = i++;

                 

                  /*

                   * value of j would be incremented first and then

                   * assigned to k.

                   */
                   /* 
                   *来 自
                    NowJava.com - 时  代  Java
                   */

                  int l = ++j;

              
展开阅读全文