write a program to input unequal numbers and display after swapping them
Answers
Answered by
3
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
Answered by
7
Answer:
hiiiiiiiiiiiii please mark me as a brainlist
Similar questions