Sunday, February 12, 2017

Java Program to sort primitive Array Elements in Ascending order in a particular range.

Ex:- we have 9 array elements index will be(0-8) like : 12,3,5,48,1,6,47,9,2 and if we want to
sort in the range like 2-7 then sorted elements will be 12,3,1,5,6,47,48,9,2

import static java.lang.System.out;
import java.util.Arrays;
class SortArray4
{
static public void main(String...alt)
{
int[] a={12,3,5,48,1,6,47,9,2};
out.println("Before Sorting : ");
for(int x:a)
out.print(x+" ");
Arrays.sort(a,2,7);
out.println("\n\nAfter Sorting : ");
for(int x:a)
out.print(x+" ");
}
}

Share this

0 Comment to "Java Program to sort primitive Array Elements in Ascending order in a particular range."

Post a Comment