09/10/16 21:26:52
>>364
public class Kadai03_5 {
public static void main(String[] args) {
int[] num = {23, 76, 48, 93, 16, 34, 87};
showArray(num);
System.out.println("\t----- Sort -----");
sort(num);
System.out.println("\t----- Result -----");
showArray(num);
}
private static void showArray(int[] a) {
if (a.length != 0) {
for (int i = 0; i < a.length - 1; i++) System.out.print(a[i] + ", ");
System.out.print(a[a.length - 1]);
}
System.out.println();
}
private static void sort(int[] a) {
for (int i = 0; i < a.length - 1; i++) for (int j = i + 1; j < a.length; j++) {
if (a[i] < a[j]) {
System.out.print("Exchange num[" + i + "]=" + a[i] + " for num[" + j + "]=" + a[j] + " ");
int b = a[i]; a[i] = a[j]; a[j] = b;
showArray(a);
}
}
}
}