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. }
  • 相关阅读:
    ssm接收界面提交的参数为空
    Servlet[jsp]的Servlet.service()引发了具有根本原因的异常无法在web.xml或使用此应用程序部署的jar文件中解析绝对uri:[http://java.sun.com/jsp/jstl/core]
    Invalid bound statement (not found)
    Data truncation: Incorrect datetime value: '' for column 'create_time' at row 1 问题
    4月29日:毕业设计计划
    4月25日:毕业设计计划
    4月24日:毕业设计计划
    4月23日:毕业设计计划
    2020年寒假学习进度(二)
    2020年寒假学习进度(一)
  • 原文地址:https://www.cnblogs.com/Yxxxxx/p/6858671.html
Copyright © 2011-2022 走看看