title: JAVA: Sorting an array in descending order
body: <p>I'm trying to sort an array in descending order, I know there are many examples of sorting an array online, but I just wanted to try and do it my own way (just trying to test to see if algorithm could actually work). But some reason, I'm unable to output the array with the result stored, I've tried using System.out.println(Arrays.toString(myList)); and printing them one at time, it works for one the arrays i created, but when trying to modify the array through a loop, it refused to output anything, no error, nothing as though nothing is there. Your help would be appreciated. see code below. Thanks.</p>
  
  <pre><code>import java.util.Arrays;
  
  public class TestArray {
  
     public static void main(String[] args) {
        double[] myList = {1.9, 2.9, 9.2, 3.4, 4.2, 6.7, 3.5};
        double[] sortedList = new double[7] ; 
  
  
        // Print all the array elements
        for (double i: myList) {
           System.out.println(i + " ");
        }
  
        // Summing all elements
        double total = 0;
        for (double x: myList) {
           total += x;
        }
        System.out.println("Total is " + total);
  
        // Finding the largest element
        double max = myList[0];
        int m, z = 0;
  
        for (double k: myList) {
           if (k &gt; max) max = k;
        }
  
        do{
          for (int i = m; i &lt; myList.length; i++) {
            if (myList[i] &gt; max){      
               max = myList[i];  
               z = i;
            }
          }
  
          sortedList[m] = max;
          myList[z] =0;
          m++;
  
        } while(m &lt; myList.length);
  
        System.out.println("Max is " + max);
        //System.out.println(Arrays.toString(myList)); 
        for (double y: sortedList) {
           System.out.println(y + " ");
        }
     }
  }
  </code></pre>