From 3064b7eda27c05bb409ae97338cce26294226c87 Mon Sep 17 00:00:00 2001 From: Tejbirsingh7878 Date: Thu, 28 Oct 2021 11:52:38 +0530 Subject: [PATCH] Create swap_two_num_without_using_temp_variable.java --- swap_two_num_without_using_temp_variable.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 swap_two_num_without_using_temp_variable.java diff --git a/swap_two_num_without_using_temp_variable.java b/swap_two_num_without_using_temp_variable.java new file mode 100644 index 0000000..ae0d5c1 --- /dev/null +++ b/swap_two_num_without_using_temp_variable.java @@ -0,0 +1,16 @@ +import java.util.*; +class SwapTwo{ + public static void main(String a[]) + { + System.out.println("Enter the value of x and y"); + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + System.out.println("before swapping numbers: "+a +" "+ b); + /*Swapping*/ + a = a + b; + b = a - b; + a = a - b; + System.out.println("After swapping: "+a +" " + b); + } +}