zoukankan      html  css  js  c++  java
  • java冒泡排序

    1. public class Maopao {  
    2.     public static void main(String[] args) {  
    3.         int[] array={1,2,5,3,10,21,0};  
    4.         getSortD_X(array);  
    5.         getSortX_D(array);  
    6.     }  
    7.     public static void getSortD_X(int[] array){  
    8.         for (int i = 0; i array.length; i++) {  
    9.             for(int j=0;j<array.length-1;j++){  
    10.                 if(array[i]>array[j]){  
    11.                     int temp=array[i];  
    12.                     array[i]=array[j];  
    13.                     array[j]=temp;  
    14.                 }  
    15.             }  
    16.         }  
    17.         System.out.print("从大到小:");  
    18.         for (int i = 0; i array.length; i++) {  
    19.             if(i==array.length-1){  
    20.                 System.out.println(array[i]);  
    21.             }else{  
    22.                 System.out.print(array[i]+",");  
    23.             }  
    24.         }  
    25.     }  
    26.     public static void getSortX_D(int[] array){  
    27.         for (int i = 0; i <array.length; i++) {  
    28.             for(int j=0;j<array.length-i-1;j++){  
    29.                 if(array[j]>array[j+1]){  
    30.                     int temp=array[j];  
    31.                     array[j]=array[j+1];  
    32.                     array[j+1]=temp;  
    33.                 }  
    34.             }  
    35.         }  
    36.         System.out.print("从小到大:");  
    37.         for (int i = 0; i array.length; i++) {  
    38.             if(i==array.length-1){  
    39.                 System.out.println(array[i]);  
    40.             }else{  
    41.                 System.out.print(array[i]+",");  
    42.             }  
    43.         }  
    44.     }  
    45. }
  • 相关阅读:
    AndroidStudio开发体温上报系统------问题总结
    AndroidStudio--app是如何运行的
    sqlite操作
    sqlite数据库
    Android Service
    echart自定义主题
    vue监听数组变化
    Django:数据库驱动安装
    pycharm链接mysql报错: Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
    Django2.2:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence
  • 原文地址:https://www.cnblogs.com/Yxxxxx/p/6858671.html
Copyright © 2011-2022 走看看