Source Code
import java.util.Scanner;
class InterChangeNo{
public void swap(){
int a, b;
System.out.println("Enter the value of a and b:");
Scanner in = new Scanner(System.in);
a = in.nextInt();
b = in.nextInt();
System.out.println("Before Swapping\nx = "+a+"\ny = "+b);
a = a + b;
b = a - b;
a = a - b;
System.out.println("After Swapping\nx = "+a+"\ny = "+b);
}
}
class Main
{
public static void main(String args[])
{
InterChangeNo obj=new InterChangeNo();
obj.swap();
}
}
No comments: