java编程中 对int[]a={25.24.12.76.98.101.90.28}数组进行冒泡
答案:3 悬赏:10 手机版
解决时间 2021-11-09 11:55
- 提问者网友:星軌
- 2021-11-08 14:29
java编程中 对int[]a={25.24.12.76.98.101.90.28}数组进行冒泡
最佳答案
- 五星知识达人网友:不想翻身的咸鱼
- 2021-11-08 15:09
int a[] = {45, 23, 18, 10, 6, 8, 67, 98, 30, 50};
//泡沫排序法
for (int i=0;i {
for (int j=0;j {
if (a[j+1]>a[j])
{
int temp = a[j+1]; //交换阵列元素
a[j+1]=a[j];
a[j]= temp;
}
}
}
for (int i=0;i System.out.print(a[i]+" | ");
System.out.println("
= = = = = = = = = = = = = =");
int max = a[0];
int min = a[a.length-1];
System.out.println("本阵列最大值= "+max+"
本阵列最小值= "+min);
//泡沫排序法
for (int i=0;i {
for (int j=0;j {
if (a[j+1]>a[j])
{
int temp = a[j+1]; //交换阵列元素
a[j+1]=a[j];
a[j]= temp;
}
}
}
for (int i=0;i System.out.print(a[i]+" | ");
System.out.println("
= = = = = = = = = = = = = =");
int max = a[0];
int min = a[a.length-1];
System.out.println("本阵列最大值= "+max+"
本阵列最小值= "+min);
全部回答
- 1楼网友:神的生死簿
- 2021-11-08 17:07
int temp;
for(int i=0;i for(int j=i+1;j temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
//从小到大排序。
for(int i=0;i for(int j=i+1;j temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
//从小到大排序。
- 2楼网友:低血压的长颈鹿
- 2021-11-08 16:35
public static void main(String[] args) {
int[]a={25,24,12,76,98,101,90,28};
for (int i = 0; i < a.length-i-1; i++) {
for (int j = 0; j < a.length-1-i; j++) {
if (a[j]>a[j+1]) {
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
int[]a={25,24,12,76,98,101,90,28};
for (int i = 0; i < a.length-i-1; i++) {
for (int j = 0; j < a.length-1-i; j++) {
if (a[j]>a[j+1]) {
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯