Java Sort
double Array
import
java.util.Arrays;
public class
SortDoubleArrayExample
{
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]);
}
}
Java Sort float
Array
import
java.util.Arrays;
public class
SortFloatArrayExample
{
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]);
}
}
Java Sort int
Array
import
java.util.Arrays;
public class
SortIntArrayExample
{
public static void
main(String[] args)
{
int[] i1 = new
int[]{3,2,5,4,1};
System.out.print("Original
Array : ");
for(int index=0; index
< i1.length ; index++)
System.out.print("
" + i1[index]);
Arrays.sort(i1);
System.out.print("Sorted
int array : ");
for(int index=0; index
< i1.length ; index++)
System.out.print("
" + i1[index]);
int[] i2 = new
int[]{5,2,3,1,4};
Arrays.sort(i2,1,4);
System.out.print("Partially
Sorted int array : ");
for(int index=0; index
< i2.length ; index++)
System.out.print("
" + i2[index]);
}
}
Java Sort long
Array
import
java.util.Arrays;
public class
SortLongArrayExample
{
public static void
main(String[] args)
{
long[] l1 = new
long[]{3,2,5,4,1};
System.out.print("Original
Array :\t ");
for(int index=0; index
< l1.length ; index++)
System.out.print("
" + l1[index]);
Arrays.sort(l1);
System.out.print("\nSorted long array :\t ");
for(int index=0; index
< l1.length ; index++)
System.out.print("
" + l1[index]);
long[] l2 = new
long[]{5,2,3,1,4};
Arrays.sort(l2,1,4);
System.out.print("\nPartially
Sorted long array :\t ");
for(int index=0; index
< l2.length ; index++)
System.out.print("
" + l2[index]);
}
}
Java Sort short
Array
import
java.util.Arrays;
public class
SortShortArrayExample
{
public static void
main(String[] args)
{
short[] s1 = new
short[]{3,2,5,4,1};
System.out.print("Original
Array :\t ");
for(int index=0; index
< s1.length ; index++)
System.out.print("
" + s1[index]);
Arrays.sort(s1);
System.out.print("\nSorted
short array :\t ");
for(int index=0; index
< s1.length ; index++)
System.out.print("
" + s1[index]);
short[] s2 = new
short[]{5,2,3,1,4};
Arrays.sort(s2,1,4);
System.out.print("\nPartially
Sorted short array :\t ");
for(int index=0; index
< s2.length ; index++)
System.out.print("
" + s2[index]);
}
}
No comments:
Post a Comment