title: Array elements become 0 after applying Array.sort() function
body: <p>I am trying to sort an array of integers using <code>Arrays.sort()</code> method. After calling this method, the array elements are becoming 0.</p>
  
  <p>Below is my code</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.Scanner;
  
  public class WillMuggerWin {
  
    public static void main(String ar[]){
       int t,n=10,m=5,sum=0,flag=0;
       int notes[]=new int[20];
  
       Scanner s=new Scanner(System.in);
       t=s.nextInt();
       for(int i=0;i&lt;t;i++){
           n=s.nextInt();
           m=s.nextInt();
           int temp=m;
          // System.out.println("m:"+m+"n:"+n);
           for(int j=0;j&lt;n;j++){
               notes[j]=s.nextInt();
  
           }
           System.out.println("note:"+notes[0]+" "+notes[1]+" "+notes[2]);
           Arrays.sort(notes);
           System.out.println("note:"+notes[0]+" "+notes[1]+" "+notes[2]);
           //System.out.println("note1"+notes[0]);
           for(int k=n-1;k&gt;=0;k--){
               //System.out.println("notes "+notes[k]);
               if(notes[k]&lt;=temp){
                   sum=sum+notes[k];
                   System.out.println("sum: "+sum);
                   temp=temp-sum;
                   if(temp==0){
                       flag=1;
                       break;
                   }
               }
           }
           if(flag==1)
           System.out.println("Yes");
           else
               System.out.println("No");
           flag=0;
           sum=0;
       }
    }
  }
  </code></pre>
  
  <p>Input:</p>
  
  <blockquote>
    <p>5 3 3 1 1 1  </p>
  </blockquote>
  
  <p>Output:</p>
  
  <blockquote>
    <p>note:1 1 1<br>
    note:0 0 0<br>
    sum: 0<br>
    sum: 0<br>
    sum: 0<br>
    No</p>
  </blockquote>
  
  <p>What is wrong with my code?</p>