public class Homework {
public static main (String[]rags){
int[] a = new int[10];
Random rand = new Random();
// 乱序
for (int i = 0; i < a.length; i++) {
a[i] = rand.nextInt(100) + 1;
Random rand = new Random();
// 乱序
for (int i = 0; i < a.length; i++) {
a[i] = rand.nextInt(100) + 1;
}
System.out.println(Arrays.toString(a));
// 升序
for (int m = 0; m < a.length; m++) {
for (int n = 0; n < a.length - 1; n++) {
if (a[n] > a[n + 1]) {
int t = a[n];
a[n] = a[n + 1];
a[n + 1] = t;
}
}
}
System.out.println(Arrays.toString(a));
// 降序
for (int m = 0; m < a.length; m++) {
for (int n = 0; n < a.length - 1 - m; n++) {
if (a[n] < a[n + 1]) {
int t = a[n];
a[n] = a[n + 1];
a[n + 1] = t;
}
}
}
System.out.println(Arrays.toString(a));
}
}
System.out.println(Arrays.toString(a));
// 升序
for (int m = 0; m < a.length; m++) {
for (int n = 0; n < a.length - 1; n++) {
if (a[n] > a[n + 1]) {
int t = a[n];
a[n] = a[n + 1];
a[n + 1] = t;
}
}
}
System.out.println(Arrays.toString(a));
// 降序
for (int m = 0; m < a.length; m++) {
for (int n = 0; n < a.length - 1 - m; n++) {
if (a[n] < a[n + 1]) {
int t = a[n];
a[n] = a[n + 1];
a[n + 1] = t;
}
}
}
System.out.println(Arrays.toString(a));
}
}