Function To Sort Array Java Code Example

Snippet 1

  import java. util. Arrays;
Arrays. sort(array); 

Snippet 2

  public class InsertSort {  public static void main (String [] args) {   int [] array = {45,12,85,32,89,39,69,44,42,1,6,8};   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]);   }  }} 

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *