Java Program to Sorting an Array

Here is simple java program for sorting an array:-

import java.io.*;
import java.lang.*;
class sort_array
{
public static void main(String args[]) throws IOException
{
int r,i,j,temp;
int a[]=new int [20];
int b[]=new int [20];
DataInputStream ds=new DataInputStream(System.in);
System.out.println(“Enter the Range”);
r=Integer.parseInt(ds.readLine());
System.out.println(“Enter the array for sorting”);
for(i=0;ia[i]=Integer.parseInt(ds.readLine());
for(i=0;i{
for(j=0;j{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println(“The array after sorting is”);
for(i=0;iSystem.out.println(a[i]);
}
}

Add Comment