title: How to sort BigDecimals without swapping .12 and 0.12?
body: <p>.12 and 0.12 are being swapped while sorting in descending order. Actually if the same numbers exist they have to be printed in the order they were received in.</p>
  <blockquote>
  <p>Java's BigDecimal class can handle arbitrary-precision signed decimal
  numbers. Let's test your knowledge of them!</p>
  <p>Given an array, <code>s</code>, of <code>n</code> real number strings, sort them in descending
  order — but wait, there's more! Each number must be printed in the
  exact same format as it was read from stdin, meaning that <code>.1</code> is
  printed as <code>.1</code>, and <code>0.1</code> is printed as <code>0.1</code>. If two numbers represent
  numerically equivalent values (eg <code>.1==0.1</code>), then they must be listed
  in the same order as they were received as input).</p>
  </blockquote>
  <pre><code>import java.math.BigDecimal;
  import java.util.*;
  class Solution{
  
      public static void main(String []args){
          //Input
          Scanner sc= new Scanner(System.in);
          int n=sc.nextInt();
          String []s=new String[n+2];
          for(int i=0;i&lt;n;i++){
              s[i]=sc.next();
          }
          sc.close();
          BigDecimal[] d=new BigDecimal[n];
           for(int i=0;i&lt;n;i++){
            d[i]=new BigDecimal(s[i]);
          }
          for(int i=0;i&lt;n;i++)
          {
              for(int j=i+1;j&lt;n;j++)
              {
                  if(d[j].compareTo(d[i]) == 1)
                  {
                      BigDecimal t=d[i];
                      d[i]=d[j];
                      d[j]=t;
                      String stmp = s[i];
                      s[i] = s[j];
                      s[j] = stmp;
                  }
              }
          }
          
  
          
          //Output
          for(int i=0;i&lt;n;i++)
          {
              System.out.println(s[i]);
          }
      }
  
  }
  </code></pre>
  <p>Input:</p>
  <pre><code>9
  -100
  50
  0
  56.6
  90
  0.12
  .12
  02.34
  000.000
  </code></pre>
  <p>Expected output:</p>
  <pre><code>90
  56.6
  50
  02.34
  0.12
  .12
  0
  000.000
  -100
  </code></pre>
  <p>Actual output:</p>
  <pre><code>90
  56.6
  50
  02.34
  .12
  0.12
  0
  000.000
  -100
  </code></pre>