public class NumberSwap {
public static void main(String[] args) {
int a=10;
int b=20;
System.out.println("Value of a before swapping is: "+a+" and value of b before swapping "+b);
b=a+b;
a=b-a;
b=b-a;
System.out.println("Value of a after swapping is: "+a+" and value of b after swapping "+b);
}
}
public static void main(String[] args) {
int a=10;
int b=20;
System.out.println("Value of a before swapping is: "+a+" and value of b before swapping "+b);
b=a+b;
a=b-a;
b=b-a;
System.out.println("Value of a after swapping is: "+a+" and value of b after swapping "+b);
}
}
Output:
Value of a before swapping is: 10 and value of b before swapping 20
Value of a after swapping is: 20 and value of b after swapping 10