by Dinesh Thakur Category: array

Algorithm for SortinganArray:

step 1: set temp=0

step 2: read arr_size

step 3: create an integer array a[] of size arr_size

step 4: initialize i=0

step 5: repeat through step-11 while i less than a.length

step 6: read a[i]

step 7: initialize j=0

step 8: repeat through step-l0 while j less than a.length

step 9: if a[i] less than a[j] then interchange value of a[i] and a[j]

step 10: j=j+1

step 11: initialize i=0

step 12: repeat through step-14 while i less than a.length

step 13: print a[i]

step 14: i=i+ 1

step 15:Exit

Here is the Java Example for Sorting an Array:

import java.util.Scanner;

public class SortinganArray
               public static void main(String args[])
               int i,j,temp=0;
               Scanner s=new Scanner(System. in) ;
               System.out.print("Enter The Size of The Array : ");
               int size=s.nextInt();
               int a[]=new int[size];
               System.out.println("Enter The array Elements");
                                    a[j]=a[i] ;
System.out.println("\nSorted an Array in Ascending Order \n");

Sorting an Array in Ascending Order

Popular Article