Jump to content

User:Wikieditor12103

From Wikipedia, the free encyclopedia

sorting in java program

public class SortASC {

    public static void main (String args[]){
       int[]arr = new int[]{5,2,8,7,1};
       int temp;
       System.out.println("element of original array");
       for(int i=0; i<arr.length; i++){
           System.out.println("arr[i]="+arr[i]);
       }
       for (int i=0; i<arr.length; i++){
           for(int j=i+1; j<arr.length; j++){
               if (arr[i]> arr[j]){
                   temp = arr[i];
                   arr[i] = arr[j];
                   arr[j] = temp;
               }
           }
       }
       
       System.out.println("element of array sorted");
       for(int i=0; arr.length> i; i++){
           System.out.println("arr[i]="+arr[i]);
       }
    }    

}