HW6.18

时间:2023-03-09 15:39:22
HW6.18

HW6.18

 public class Solution
 {
     public static void main(String[] args)
     {
         double[] array = {6.0, 4.4, 1.9, 2.9, 3.4, 2.9, 3.5};
         bubbleSort(array);
         for(double i: array)
             System.out.print(i + " ");
     }

     public static void bubbleSort(double[] array)
     {
         double temp;
         for(int i = array.length - 1; i > 0; i--)
         {
             for(int j = 0; j < i; j++)
                 if(array[j + 1] < array[j])
                 {
                     temp = array[j + 1];
                     array[j + 1] = array[j];
                     array[j] = temp;
                 }
         }
     }
 }