Java Program to Swap Numbers

This is a very basic program in Java programming language. If you are a Java beginners or want to start learning Java programming language, then this program will help you to understand the basic Java programming. In this post, I will explain about a Java program to swap two numbers with an example.

Java Program to Swap Numbers

Before executing this program I assume you have configured Java in your computer.

Copy the below program and create a file “SwapNumberProgram.java” and execute it.

Program Output

Enter number x and y
10
20
Before Swapping
x value: 10
y value: 20
After Swapping
x value: 20
y value: 10

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


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.

Article Tags: , , , , , ,