Java Program To Swap Two Numbers Without Using Third Variable

 package demo;


public class SwapNumbers {

public static void main(String[] args) {


int a = 10, b = 4;

System.out.println("Before Swapping");

System.out.println("a=" + a + " b=" + b);

a = a + b;

b = a - b;

a = a - b;

System.out.println("After Swapping");

System.out.println("a=" + a + " b=" + b);

}


}


Comments

Popular posts from this blog

3 Lines of Code And You Can Download Your Favourite Youtube Video.

Leetcode Problem(Easy) Roman to Integer

Leetcode : (Find Minimum in Rotated Sorted Array)