I want to sort an array using the swap() method as shown in the code. I want to know how to pass the array and sort it.
public class Test {
public static void main(String[] args) {
int [] ar = {9, 4, 5, 3, 1, 8, 4, 2, 0};
System.out.println(Arrays.toString(ar));
for (int i = 0; i<ar.length-1; i++){
for (int j = i+1; j<ar.length; j++){
swap(ar[i], ar[j]);
}
}
System.out.println(Arrays.toString(ar));
}
private static void swap(int i, int j) {
int temp;
if(i>j){
temp = j;
j = i;
i= temp;
}
}
}