How to Use Decrement Operator and decrement operator in Java


In this example we will show how to use increment operator (++) and decrement (–) operator in Java.

Source Code

package com.beginner.examples;

public class DecExample {

    public static void main(String[] args){
    	 int a = 5;
		 int b = 5;
		 // a--
		 int m = a--;
		 int n = b--;
		 
		 System.out.println("m = " + m);
		 System.out.println("n = " + n);
		 // --a
		 int j = --a;
		 int k = --b;
		 System.out.println("j = " + j);
		 System.out.println("k = " + k);
    }
}

Output:

m = 5
n = 5
j = 3
k = 3
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments