首页 > 代码库 > HW6.18

HW6.18

技术分享

 

 1 public class Solution 2 { 3     public static void main(String[] args) 4     { 5         double[] array = {6.0, 4.4, 1.9, 2.9, 3.4, 2.9, 3.5}; 6         bubbleSort(array); 7         for(double i: array) 8             System.out.print(i + " "); 9     }10 11     public static void bubbleSort(double[] array)12     {13         double temp;14         for(int i = array.length - 1; i > 0; i--)15         {16             for(int j = 0; j < i; j++)17                 if(array[j + 1] < array[j])18                 {19                     temp = array[j + 1];20                     array[j + 1] = array[j];21                     array[j] = temp;22                 }23         }24     }25 }

 

HW6.18