How to write a Java Program to Swap Number Without Temporary Variable

| Last Updated: | In: Java Tutorial


In one of the previous tutorial, I have explained how to swap two numbers in java programming language. In this tutorial, I will share how to write a java program to swap number without a temporary variable.

How to write a Java Program to Swap Number Without Temporary Variable

Copy the below java program and execute it with the help Java compiler. At the end of this tutorial, I have shared the output of the following programs.

Program Output

Enter the number x and y:
30
10
Before Swapping:
30
10
After Swapping:
10
30


About: Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:

Tags: , , , , , ,