PTA冒泡排序

PTA冒泡排序_第1张图片

import java.util.*;

public class Main {


public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int a[] = new int[sc.nextInt()];
int num = sc.nextInt();
sc.nextLine();
for (int i = 0; i < a.length; i++) {
a[i] = sc.nextInt();
}
int x = 1;
while (x <= num) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
int temp;
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
x = x + 1;
}
for (int i = 0; i < a.length - 1; i++) {
System.out.print(a[i] + " ");
}
System.out.print(a[a.length - 1]);


}

}

你可能感兴趣的:(JAVASE)