提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
通常,我们需要在变量的值(例如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);
}
}