-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySorting.java
More file actions
55 lines (39 loc) · 1.18 KB
/
ArraySorting.java
File metadata and controls
55 lines (39 loc) · 1.18 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
import java.util.Arrays;
public class ArraySorting{
int[] squarenumber = new int[numbers.length];
for(sortsquare = 0 ; sortsquare < number.length; sortsquare++){
squarenumber[sortsquare] = number[sortsquare] * number[sortsquare];
}
for(int firstloop = 0; firstloop < squarednumber.length; firstloop++){
for(int secondloop = 0; secondloop < squarenumber.length -1 - firstloop; secondloop++){
if(squarednumber[firstloop] > squarednumber[firstloop + 1]){
int temps = squarednumber[firstloop];
squarednumber[firstloop] = squarednumber[firstloop + 1];
squarednumber[firstloop + 1] = temps;
}
}
}
}
return squarednumber;
}
public static void main (String[] args ){
int[] array = {7, 2, 9, 3, 0};
for(int index = array[index]; index < array.length; index++) {
int numberMin = array[index];
int numberMinIndex = index;
for(int count = index + 1; count < array.length; count++) {
if(numberMin > array[count]) {
numberMin = array[count];
numberMinIndex = count;
}
}
if(numberMinIndex != index) {
array[numberMinIndex] = array[index];
array[index] = numberMin;
}
}
System.out.print(Arrays.toString(array));
}
}
}
}