用java编写定义一个一维数组,存放10个数字,求数组中最大值和最小值(注意最好用冒泡排序)

明天急用
2024-11-30 19:38:03
推荐回答(2个)
回答1:

int []shu ={30,80,96,45,8,35};
for (int i=0;i<(shu.length-1);i++){
for (int p=0;p<(shu.length-1-i);p++){
if (shu[p]>shu[p+1]){
int huan=shu[p];
shu[p]=shu[p+1];
shu[p+1]=huan;
}
}
}
//输出冒泡排首液序的数组
//for (int l=0;l<尘慎shu.length;l++){
// System.out.print(shu[l]+"\t"派芹敬);
for (int l:shu){
//System.out.print(l+"\t");
System.out.print("第"+l+"个数为:"+l);

}

}

回答2:

冒泡排序就是for套for啊