---
title: "How can I swap two variables without using a third variable?"  
description: "How can I swap two variables without using a third variable?"  
author: "Rajesh Goswami"  
published: 2011-05-07  
updated: 2011-05-07  
canonical: https://www.mindstick.com/forum/236/how-can-i-swap-two-variables-without-using-a-third-variable  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How can I swap two variables without using a third variable?

[Problem in making](https://www.mindstick.com/forum/81/problem-in-making-attribute-in-c-sharp) a [swap](https://www.mindstick.com/forum/34027/how-to-swap-the-values-of-two-columns-in-sql-server) [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) in [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) without using a [third variable](https://www.mindstick.com/forum/55171/write-a-program-in-java-to-swap-two-numbers-without-using-third-variable-and-with-third-variable).

## Replies

### Reply by Amit Singh

we can swap using only two variable **for example**

int a=5,b=10;a=a+b; b=a-b; a=a-b;

check it.


---

Original Source: https://www.mindstick.com/forum/236/how-can-i-swap-two-variables-without-using-a-third-variable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
