Java Sort Double Array
Chapter:
Data Structures
Last Updated:
19-09-2016 16:20:11 UTC
Program:
/* ............... START ............... */
import java.util.Arrays;
public class JavaSortDoubleArray {
public static void main(String[] args) {
double[] d1 = new double[] { 3, 2, 5, 4, 1 };
System.out.print("Original Array :\t ");
for (int index = 0; index < d1.length; index++)
System.out.print(" " + d1[index]);
Arrays.sort(d1);
System.out.print("\nSorted double array :\t ");
for (int index = 0; index < d1.length; index++)
System.out.print(" " + d1[index]);
double[] d2 = new double[] { 5, 2, 3, 1, 4 };
Arrays.sort(d2, 1, 4);
System.out.print("\nPartially Sorted double array :\t ");
for (int index = 0; index < d2.length; index++)
System.out.print(" " + d2[index]);
}
}
/* ............... END ............... */
Output
Original Array : 3.0 2.0 5.0 4.0 1.0
Sorted double array : 1.0 2.0 3.0 4.0 5.0
Partially Sorted double array : 5.0 1.0 2.0 3.0 4.0
Tags
Sort Double Array, Java, Data Structures