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