Program :
import java.io.*; // importing input/output package
class Sort // class definition
{
public static void main(String args[]) // main function
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
// invoking input class
int a[]=new int[10]; // initializing array
int i=0;
int j=0; // initializing variables
int n=0;
int t=0;
try // Exception handling
{
System.out.println("Enter no: of elements");
// print statement
n=Integer.parseInt(in.readLine()); // converting input received to integer
System.out.println("Enter the elements"); // print statement
for(i=0;i
a[i]=Integer.parseInt(in.readLine()); // converting input received to integer
}
for(i=0;i
for(j=i+1;j
if (a[i]>a[j]) // conditional statement
{
t=a[i];
a[i]=a[j]; // swapping values
a[j]=t;
}
}
}
System.out.println("Sorted array is:"); // print statement
for(i=0;i
System.out.println(+a[i]); // print statement
}
}
catch(Exception e) // catching the user defined exception
{ }
}
}
Saturday, November 3, 2007
Sorting Numbers
Posted by MarchingSoul at 8:33 AM
Labels: Data Structures
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment