泡沫排序为什么错知道的请告诉我,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/03 05:23:25
public class test {

public test() {
}
public static void main (String[] args) {
int a[]={1,23,34,13};
int i=0;
int j=0;
int t=0;
for(i=0;i<3;i++)
for(j=i+1;j<4;j++)
if(a[i]>a[j])
t=a[i];
a[i]=a[j];
a[j]=t;
System.out.println(a[i]);
}

}
运行通过拉

大哥 你的 花括号呢

public class test {

public test() {
}
public static void main (String[] args) {
int a[]={1,123,565,6,2,23,34,13};
int i=0;
int j=0;
int t=0;
for(i=0;i<3;i++) {
for(j=i+1;j<4;j++) {
if(a[i]>a[j]) {
t=a[i];
a[i]=a[j];
a[j]=t;

}

}

}

}

}

恩,楼上的说得对,没花括号.

你的循环语句不是按你想的去运行的.