Java Topics

Sort the elements in Ascending order

 public class AscendingOrder {


public static void main(String[] args) {

int[] ar= {20,60,10,46};

for(int i=0;i<ar.length;i++) {

for(int j=i+1;j<ar.length;j++) {

if(ar[i]>ar[j]) {

int temp=ar[i];

ar[i]=ar[j];

ar[j]=temp;

}

}

}

      for(int k=0;k<ar.length;k++) {

      System.out.print(ar[k]+" ");

      }

}

}


Output:

10 20 46 60