write a program to input unequal numbers and display after swapping them
Share
write a program to input unequal numbers and display after swapping them
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
CODE:
import java.util.*;
class Swapping
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 2 numbers");
int a=sc.nextInt();
int b=sc.nextInt();
a=a+b;
b=a-b;
a=a-b;
System.out.println("Swapped value of a :"+b);
System.out.println("Swapped value of b :"+a);
}
}
LOGIC:
First note the step :
a = a + b
Then b = a - b
= > b = a + b - b [ from above ]
= > b = a
then a = a - b
= > a = a - ( a - b )
= > a = a - a + b
= > a = b
That is the way they are swapped !
Explanation:
Mark me as brainliest and thanks me
Answer:
hiiiiiiiiiiiii please mark me as a brainlist