WRITE A BLUE J PROGRAM To swap two numbers using third variable
Sample input :a=23,b=56
Sample output :a=56,b=23
PLEASE ANSWER IT FAST
Answers
Answer:
*Mark as the Brainliest if useful*
Explanation:
X= 25 (First number), Y= 23 (second number)
Swapping Logic:
X = X + Y = 25 +23 = 48
Y = X - Y = 48 - 23 = 25
X = X -Y = 48 - 25 = 23
and the numbers are swapped as X =23 and Y =25.
Algorithm
STEP 1: START
STEP 2: ENTER x, y
STEP 3: PRINT x, y
STEP 4: x = x + y
STEP 5: y= x - y
STEP 6: x =x - y
STEP 7: PRINT x, y
STEP 8: END
Java Program
import java.util.*;
class Swap
{
public static void main(String a[])
{
System.out.println("Enter the value of x and y");
Scanner sc = new Scanner(System.in);
/*Define variables*/
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println("before swapping numbers: "+x +" "+ y);
/*Swapping*/
x = x + y;
y = x - y;
x = x - y;
System.out.println("After swapping: "+x +" " + y);
}
}
Output:
Enter the value of x and y
23 43
before swapping numbers: 23 43
After swapping: 43 23
Answer:
check the image for solution
Explanation:
main algorithm is
t= x;
x=y;
y=t;
hope it helps n if it helps... mark it !
![](https://hi-static.z-dn.net/files/d92/bcd975153f3a5287b8663acfa69603e9.jpg)