0 votes

1 Answer

0 votes
by
How to sort array in java?

public class InsertSort {

  public static void main (String [] args) {

   int [] array = {10,20,30,60,70,80,2,3,1};

   int temp;

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

    for (int j = i; j > 0; j--) {

     if (array[j] < array [j - 1]) {

      temp = array[j];

      array[j] = array[j - 1];

      array[j - 1] = temp;

     }

    }

   }

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

     System.out.println(array[i]);

   }

  }

}
...