---
title: "Discussion on \"Swapping Two Numbers\" | Hashnode"
description: "Discussion on \"Swapping Two Numbers\". Using a temp variable\nint a = 5;\nint b = 10;\n\nint temp = a;\na = b;\nb = temp;\n\nSystem.out.println(\"a = \" + a); // Output: a = 10\nSystem.out.println(\"b = \" + b); // Output: b = 5\n\nWithout Using a temp variable (using addition and subtraction):\nint a = ..."
url: "https://hashnode.com/posts/swapping-two-numbers/65da207637d5b5d24f61ed3e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Swapping Two Numbers](https://srujanmelam.hashnode.dev/swapping-two-numbers?utm_source=hashnode&utm_medium=feed)

Using a temp variable int a = 5; int b = 10; int temp = a; a = b; b = temp; System.out.println("a = " + a); // Output: a = 10 System.out.println("b = " + b); // Output: b = 5 Without Using a temp variable (using addition and subtraction): int a = ...

Feb 24, 2024 · 1 min read · srujanmelam.hashnode.dev  
Read the article

-   [#coding](https://hashnode.com/tag/coding)
-   [#java](https://hashnode.com/tag/java)
-   [#programming-tips](https://hashnode.com/tag/programming-tips)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#opensource](https://hashnode.com/tag/opensource)

## Written by

[Melam Jai Bala Srujan](https://hashnode.com/@srujanmelam)

@srujanmelam

  
[View profile](https://hashnode.com/@srujanmelam)

Im a software Development Engineer

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
