1public static void swap(int[] a, int i, int j){
2 int temp = a[i];
3 a[i] = a[j];
4 a[j] = temp;
5}
1public class Exercise15 {
2 public static void main(String[] args) {
3 // int, double, float
4 int a, b;
5 a = 15;
6 b = 27;
7 System.out.println("Before swapping : a, b = "+a+", "+ + b);
8 a = a + b;
9 b = a - b;
10 a = a - b;
11 System.out.println("After swapping : a, b = "+a+", "+ + b);
12 }
13
14}
15
16
1// a, b can be a numeric value
2a += b; // a = a + b
3b = a - b; // b = (a + b) - b = a ---> b=a
4a -= b; // a = (a + b) - (a) = b ---> a=b