import java.io.*;
import java.util.Arrays;
public class Hello {
public static void main(String[] args) {
int[] ns = {28, 12, 89, 73, 65, 18, 96, 50, 8, 36};
// 排序前:
System.out.println(Arrays.toString(ns));
// TODO:
for (int i = ns.length - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (ns[i] > ns[j]) {
int tmp = ns[j];
ns[j] = ns[i];
ns[i] = tmp;
}
// 排序后:
if (Arrays.toString(ns).equals("[96, 89, 73, 65, 50, 36, 28, 18, 12, 8]")) {
System.out.println("测试成功");
} else {
System.out.println("测试失败");
Sign in to make a reply
胖胖
import java.io.*;
import java.util.Arrays;
public class Hello {
public static void main(String[] args) {
int[] ns = {28, 12, 89, 73, 65, 18, 96, 50, 8, 36};
// 排序前:
System.out.println(Arrays.toString(ns));
// TODO:
for (int i = ns.length - 1; i > 0; i--) {
for (int j = i - 1; j >= 0; j--) {
if (ns[i] > ns[j]) {
int tmp = ns[j];
ns[j] = ns[i];
ns[i] = tmp;
}
}
}
// 排序后:
System.out.println(Arrays.toString(ns));
if (Arrays.toString(ns).equals("[96, 89, 73, 65, 50, 36, 28, 18, 12, 8]")) {
System.out.println("测试成功");
} else {
System.out.println("测试失败");
}
}
}