java实现冒泡排序
importjava.util.Arrays;publicclass_5_7_1{publicstaticvoidmain(String[]args){//TODOAut...
import java.util.Arrays;
public class _5_7_1 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
int []a = {25,24,12,76,98,101,90,28};
int i,tmp;
for(i=0;i<a.length-1;i++)
{
if(a[i]>a[i+1])
{
tmp = a[i];
a[i] = a[i+1];
a[i+1] = tmp;
}
}
System.out.println(Arrays.toString(a));
}
}
为什么结果是[24, 12, 25, 76, 98, 90, 28, 101]?? 展开
public class _5_7_1 {
public static void main(String[] args)
{
// TODO Auto-generated method stub
int []a = {25,24,12,76,98,101,90,28};
int i,tmp;
for(i=0;i<a.length-1;i++)
{
if(a[i]>a[i+1])
{
tmp = a[i];
a[i] = a[i+1];
a[i+1] = tmp;
}
}
System.out.println(Arrays.toString(a));
}
}
为什么结果是[24, 12, 25, 76, 98, 90, 28, 101]?? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询