In this example we will show the method to swap number without using third variable in Java.
Source Code
package com.beginner.examples;
public class SwapNum {
public static void main(String[] args){
int m = 2020;
int n = 6;
//swap the value
m = m + n;
n = m - n;
m = m - n;
System.out.println("m = " + m + " and n = " + n);
}
}
Output:
m = 6 and n = 2020