Monday, 23 February 2015

Filled Under:

How To Sort Array In Ascending Order Using Sort Method

In last our last tutorial we  try to illustrate How to sort numbers in ascending order but as we can see it is difficult,instead of using loop for sorting we can also use sort() method it arrange array in ascending order it has two version.The first version,sort entire array.
static void sort(int array[])
And second method allow you to sort array within range.its shown below
staic void sort(int array[],int start,int end)
In this tutorial we use loop to print array,The implementation of sort method shown below

CODING:

import java.util.*;
class arraysort
{
public static void main(String args[])
{
int arr[] = {100,20,40,60,70,10};
System.out.println("Before sorting:");
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
Arrays.sort(arr);
System.out.println("After sorting:");
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}

}
}

OUTPUT:



0 comments:

Post a Comment