Code:
import java.io.*;
import java.lang.*;
import java.util.Scanner;
class sorting
{
public static void main(String args[])
{
int a,b,n,i,temp,j;
Scanner in=new Scanner(System.in);
System.out.print("How many numbers to sort : ");
n=in.nextInt();
int[] h= new int[n];
System.out.println("Enter the "+n +" Elements");
for(i=0;i<n;i++)
{
h[i]=in.nextInt();
}
for(i=0;i<n-1;i++)
{
for(j=0;j<(n-i-1);j++)
{
if(h[j]>h[j+1])
{
temp=h[j];
h[j]=h[j+1];
h[j+1]=temp;
}
}
}
System.out.println("sorted list");
for(i=0;i<n;i++)
{
System.out.println(h[i]);
}
}
}
No comments:
Post a Comment