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