Java examples for Language Basics:Operator
Often we need to add or subtract one to the value of a variable, say x.
This can be done as follows:
public class Main { public static void main(String arg[]) { int x = 1;// w w w. ja v a 2 s . co m 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); } }