public class Paixu {
public static void main(String[] args) {
// Paixu px=new Paixu();
MaoPaoSort mp=new MaoPaoSort();
//上面這裡就開始報錯了:No enclosing instance of type Paixu is accessible. Must qualify the allocation with an enclosing instance of type Paixu (e.g. x.new A() where x is an instance of Paixu).
}
class MaoPaoSort {
public void test1() {
int a[] = { 1, 1234, 356, 123, 56346, 73, 45342342, 1, 3, 56, };
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < i - 1; j++) {
if (a[i] < a[j]) {
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
System.out.println(a[j]);
}
}
}
}
}
}
不能在靜態函數中new,把 MaoPaoSort改成靜態的類