java编程题,期末考试的题,跪求,求大佬编写一下
发布网友
发布时间:2022-04-24 19:42
我来回答
共1个回答
热心网友
时间:2023-10-08 23:58
public class RunTest {
private static int[] arr = { 2, 5, 7, 1, 3, 4, 6, 9, 8 };
public static void main(String[] args) {
System.out.println("原始:"+Arrays.toString(arr));
new Thread() {
public void run() {
StringBuilder sd=new StringBuilder();
for(int a:arr) {
sd.append(a+" ");
}
System.out.println("反转:["+sd.reverse()+" ]");
}
}.start();
new Thread() {
public void run() {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
System.out.println("冒泡:"+Arrays.toString(arr));
}
}.start();
}
}