Computer Science, asked by anshikapjs6446, 3 days ago

Write a Java program to accept any two numbers from the user and swap their values by using a third variable. Example if x=25 & y=50 , then after swapping x will be 50 & y will be 25.

Answers

Answered by AryaGargi
0

Answer:

import java.util.Scanner;

class SwapNumbers

{

public static void main(String args[])

{

int x, y, temp;

System.out.println("Enter x and y");

Scanner in = new Scanner(System.in);

x = in.nextInt();

y = in.nextInt();

System.out.println("Before Swapping\nx = "+x+"\ny = "+y);

temp = x;

x = y;

y = temp;

System.out.println("After Swapping\nx = "+x+"\ny = "+y);

}

}

Similar questions