用冒泡法编个程序 JAVA的

用冒泡法编个程序 JAVA的
编程采用冒泡法实现对数组元素由小到大排序,冒泡法排序对相邻的两个元素进行比较,并把小的元素交换到前面。
提示:关键代码如下:
for(i=0;ifor(j=i+1;jif (intArray[i]>intArray[j]){
t=intArray[i];intArray[i]=intArray[j];intArray[j]=t;}
public class Test2 {
public static void main(String[] args){
int[] a = {7,2,23,65,43,98,21,9,17};
for(int i=0;ifor(int j=0;jif(a[i] < a[j]){
int t = 0;
t = a[j];
a[j] = a[i];
a[i] = t;
}
}
}
//显示
for(int i=0;iSystem.out.println(a[i]);
}
}
}
7,9,12,17,21,23,43,65,98
public class Test2 {
public static void main(String[] args){
int[] a = {18, 25, 7, 36, 13, 9, 89, 63};
for(int i=0;i for(int j=0;j if(a[i] < a[j]){
int t = 0;
t = a[j];
a[j] = a[i];
a[i] = t;
}
}
}
for(int i=0;i System.out.println(a[i]);
}
}
}
public class Maopao{
public static void main(String[] args){
int[] intArray={6,4,3,7,34,546,34,23,12,56,1};
int t;
for(int i=0;i for(int j=i+1;j if (intArray[i]>intArray[j]){
t=intArray[i];intArray[i]=intArray[j];intArray[j]=t;}
for(int m:intArray)
System.out.print(m+" ");
}
}
}
//卖腔排序
public class Test2 {
public static void main(String[] args){
int[] a = {18, 25, 7, 36, 13, 9, 89, 63};
for(int i=0;ifor(int j=0;jif(a[i] < a[j]){
int t = 0;
t = a[j];
a[j] = a[i];
a[i] = t;
}
}
}
//显示
for(int i=0;i<举配斗正磨a.length;i++){
System.out.println(a[i]);
}
}
}
代码不都给出来了,还编什么啊?
← 上一篇: 下一篇: →