集册 Java实例教程 自加自减

自加自减

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

532
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!

通常,我们需要在变量的值(例如x)上加上或减去1。

/**
nowjava.com - 时  代  Java
**/public class Main {  public static void main(String arg[]) {    int x = 1;    System.out.println(x);

    x=x+1; 

    System.out.println(x);

    x+=1; // compact form 

    System.out.println(x);

    x=x-1; 

    System.out.println(x);

    x-=1; // compact form 

    System.out.println(x);


  }

}