package cn.hpu.edu.hlj;
import java.util.Date;
public class Test5 {
public static void main(String[] args) {
int temp;
int[] a = { 12, 3, 11, 80, 39, 46, 77, 65, 4 };
for (int i = 0; i < a.length; i++) {
for (int j = i+1; j < a.length; j++) {
if (a[i] > a[j]) {
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
}
import java.util.Date;
public class Test5 {
public static void main(String[] args) {
int temp;
int[] a = { 12, 3, 11, 80, 39, 46, 77, 65, 4 };
for (int i = 0; i < a.length; i++) {
for (int j = i+1; j < a.length; j++) {
if (a[i] > a[j]) {
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
}
}
输出结果:
3
4
11
12
39
46
65
77
80