Use Java arithmetic assignment operators: +=, -=, *= and /=.

 


public class Main {
  public static void main(String[] args) {
    int i = 5;
    int j = 1;
    i += 5; // i = i + 5
    j -= 5; // j = j - 5
    System.out.println("i = " + i);
    System.out.println("j = " + j);
  }
}

 

The output


i = 10
j = -4
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.