-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhaseGate2Five.java
More file actions
29 lines (23 loc) · 827 Bytes
/
Copy pathPhaseGate2Five.java
File metadata and controls
29 lines (23 loc) · 827 Bytes
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
public class PhaseGate2Five {
public static int[] sortDescending(int[] numbers) {
int length = numbers.length;
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - i - 1; j++) {
if (numbers[j] < numbers[j + 1]) {
int temp = numbers[j];
numbers[j] = numbers[j + 1];
numbers[j + 1] = temp;
}
}
}
return numbers;
}
public static void main(String[] args) {
int[] input = {5, 3, 8, 1, 2};
int[] sorted = sortDescending(input);
System.out.println("Result: ");
for (int i = 0; i < sorted.length; i++) {
System.out.print(sorted[i] + " ");
}
}
}