Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Friday, August 17, 2012

CJ-19:Sorting array numbers in ascending order

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
public class ascending 
{
    public static void main(String args[])throws Exception
    {
        DataInputStream din=new DataInputStream(System.in);
        int t,i,j;
        int n=0;
        int result=0;
        int a[]=new int[10];
        System.out.println("Enter the limit :");
        n=Integer.parseInt(din.readLine());
        System.out.println("Enter the numbers :");
        for(i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(din.readLine());
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if(a[i]<a[j])
                {
                    t=a[i];
                    a[i]=a[j];
                    a[j]=t;
                }
            }
        }
        System.out.println("The numbers in ascending orer is :");
        for(i=0;i<n;i++)
            System.out.println(a[i]);   
    }   
}
=========================================================================
Output : 
Enter the limit :
3
Enter the numbers :
5
7
2
The numbers in ascending order is :
2
5
7