♣♣♣ WRITE A PROGRAM TO SORT
EXISTING ARRAY. ♣♣♣
import java.io.*;
class pro7
{
public
static void main(String args[]) throws IOException
{
int
cnt,last,i,j,temp;
int
arr[]=new int[10];
InputStreamReader
a=new InputStreamReader(System.in);
BufferedReader
b=new BufferedReader(a);
System.out.print("Enter
the total number of array : ");
last=Integer.parseInt(b.readLine());
for(cnt=0;cnt
{
System.out.print("Enter
element"+(cnt+1)+" : ");
arr[cnt]=Integer.parseInt(b.readLine());
}
for(i=1;i<=last;i++)
{
for(j=1;j<=last;j++)
{
if(arr[j-1]
{
temp=arr[j-1];
arr[j-1]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("Array
after sorting is :");
for(cnt=0;cnt
{
System.out.print(arr[cnt]+" ");
}
}
}
OUTPUT :-
Enter
the total number of array : 5
Enter
Element1 :23
Enter
Element2 :12
Enter
Element3 :45
Enter
Element4 :33
Enter
Element5 :21
Array after sorting is :
45 33 23 21 12
No comments:
Post a Comment