代码如下:


public class test1 {
    public static void main(String[] args) {
        int[] a= {25,24,12,76,98,101,90,28};
    System.out.println("排序前数组a的元素为:");
    for(int i=0;i<a.length;i++)
    {
        System.out.print("a["+i+"] = "+a[i]+"\t");
                }
    System.out.println();
    System.out.println("排序后数组a的元素为:");
    for(int i=0;i<a.length-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 j=0;j<a.length;j++) {
        System.out.print("a["+j+"]= "+a[j]+"\t");
          }
        }
    }

 

运行结果

 

java 用冒泡算法对数组进行排序(1)

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2021-04-25
  • 2021-07-31
  • 2022-03-09
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2022-01-06
  • 2021-11-11
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案