黑马程序员技术交流社区
标题:
刚学会的冒泡
[打印本页]
作者:
lshaizj
时间:
2015-5-4 21:36
标题:
刚学会的冒泡
直接上代码
class Max
{
public static void main(String[] args)
{
int [] arr = {18,27,6,81,101,15,2};//7
System.out.print("冒泡前:");
for (int a=0;a<arr.length ;a++ )
{
System.out.print(" "+arr[a]);
}
System.out.println();
getMax(arr);
}
public static void getMax(int [] a)
{
int temp=0;
for (int b=0;b<a.length ;b++ )
{
for (int c=b+1;c<a.length;c++ )
{
if (a[b]>a[c])
{
temp=a[b];
a[b]=a[c];
a[c]=temp;
}
}
}
System.out.print("冒泡后:");
for (int b=0;b<a.length;b++ )
{
System.out.print(" "+a[b]);
}
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2