Swap two numbers without using third variable in Java

By | August 6, 2020

Swap two numbers without using third variable in Java:

You have given two numbers and you have to swap two numbers without using third variable in Java. When you use a third variable its easy to to swap numbers as below.

But when you can’t use third/temporary variable then you can follow below method.

Output:

Before swapping:
x= 111
y= 222
After swapping :
x= 222
y= 111

 

Recommended Posts:

Covert String to int in Java

Star pattern programs in Java

Get last 4 chars from String

Timeout test in TestNG

How to clear an arraylist in java

Java interview questions

Real-time selenium interview questions

SQL quick reference for interview preparation

 

Source: http://www.apache.org

Tags: Swap two numbers without using third variable in Java

 

Note: If you like selenium99.com and want to contribute articles, then please send your articles at techygeeks99@gmail.com.

arrays tostring in java | selenium interview questions | Swap two numbers without using third variable in Java

Leave a Reply

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