How to use Java arithmetic assignment operators like +=, -=, *= and /=. - Java Language Basics

Java examples for Language Basics:Operator

Description

How to use Java arithmetic assignment operators like +=, -=, *= and /=.

Demo Code


public class Main {
 
        public static void main(String[] args) {
                 int i = 5;
                 int j = 10;
                 //from w  w  w .  j  ava  2 s  .co  m
                 i += 5; //same as i = i + 5
                 j -= 2; //same as j = j - 2
                 
                 System.out.println("i = " + i);
                 System.out.println("j = " + j);
               
        }
}

Result


Related Tutorials