Swap two numbers without using third variable (A java Program)

Published: 06 September 2020
on channel: Knowledge Circle
1,351
104

Dear viewers,
In this video , I will thoroughly explain how to swap(Interchange) the values of two variables without declaring any extra variable.

Code-👇

import java.util.Scanner;
class swap
{
public static void main (String[ ] args)
{
Scanner sc=new Scanner (System.in);
int a,b;
System.out.println("Enter first number");
a=sc.nextInt();
System.out.println("Enter first number");
b=sc.nextInt();
System.out.println("Numbers before swapping");
System.out.println("a="+a);
System.out.println("b="+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("Numbers after swapping");
System.out.println("a="+a);
System.out.println("b="+b);
}
}


#javaprograms
#swaptwonumbers



Follow me on Instagram 👇

  / vinay_k_jaiswal  

Follow me on facebook 👇

  / vkj21  

Follow me on twitter 👇

  / vinaykumarsmart  


On this page of the site you can watch the video online Swap two numbers without using third variable (A java Program) with a duration of hours minute second in good quality, which was uploaded by the user Knowledge Circle 06 September 2020, share the link with friends and acquaintances, this video has already been watched 1,351 times on youtube and it was liked by 104 viewers. Enjoy your viewing!