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

By Prem Tiwari in Java Programming. Updated on


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

Sharing is caring!


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

You might also like:

Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.