Java Program to Swap Two Numbers

Here you will get java program to swap numbers using temporary variable.

It can be done in following way.

temp = a

a = b

b = temp

Also Read: Java Program to Swap Two Numbers Without Using Third Variable



Enter first number: 5
Enter second number: 8

Before swap:
a = 5
b = 8

After swap:
a = 8
b = 5

Leave a Comment

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