WAP to sort a given list of number

Free Java Programs

Write a program to sort a given list of number

import java.io.*;
class sorting
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[]=new int[10],i,temp,j;
System.out.println("Enter an array of 10 numbers");
for(i=0;i<10;i++)
{
arr[i]=Integer.parseInt(br.readLine());
}

for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
System.out.println("Sorted array is");
for(i=0;i<10;i++)
{
System.out.println(arr[i]);
}
}
}

Post a Comment

Previous Post Next Post