-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortingArray.java
More file actions
76 lines (67 loc) · 1.91 KB
/
Copy pathSortingArray.java
File metadata and controls
76 lines (67 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package exersize; //---by Abd---//
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class SortingArray {
public static void main(String[] args) {
Integer arr[]=new Integer[5];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the element in an Array : ");
for(int i=0; i<arr.length;i++)
{
arr[i]=sc.nextInt();
}
//---------------------------SORTING ASCENDING ORDER ---------------------------------//
System.out.println("Sorting Ascending Order :");
for(int i=0; i<arr.length; i++)
{
for(int j=0;j<arr.length; j++)
{
if(arr[i]<arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i]+" ");
}
//------------------------------------------------------------------------------------//
//----------------------------SORTING DESCENDING ORDER--------------------------------//
System.out.println("\nSorting Descending order :");
for(int i=0; i<arr.length; i++)
{
for(int j=0;j<arr.length; j++)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i]+" ");
}
//-----------------------------------------------------------------------------------//
//----------------------------SORTING ASCENDING ORDER USING INBUILD FUNCTION-------------//
System.out.println("\nSorting Ascending Order Using Inbuild Function :");
Arrays.sort(arr);
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i]+" ");
}
//----------------------------SORTING DESCENDING ORDER USING INBUILD FUNCTION------------//
System.out.println("\nSorting Ascending Order Using Inbuild Function :");
Arrays.sort(arr,Collections.reverseOrder());
for(int i=0; i<arr.length; i++)
{
System.out.print(arr[i]+" ");
}
}
}