Computer Science, asked by mahtabhussain202, 7 months ago

WAP to input two values, swap them and print their values.

Answers

Answered by anindyaadhikari13
4

Question:-

Write a program to input two values and swap them.

Program:-

In Java.

class Swap

{

static void main(int a, int b)

{

System.out.println("Before swapping. ");

System.out.println("a: "+a);

System.out.println("b: "+b);

int c=a;

a=b;

b=c;

System.out.println("After swapping. ");

System.out.println("a: "+a);

System.out.println("b: "+b);

}

}

In Python.

a=int(input("Enter the value of a: "))

b=int(input("Enter the value of b: "))

print("Before swapping,")

print("a: ",a)

print("b: ",b)

c=a

a=b

b=c

print("After Swapping, ")

print("a: ",a)

print("b: ",b)

Similar questions