title: how to find the sum of two elements in an array closest to zero
body: <p>How to find two elements from an array whose sum is closest to zero but not zero(note: -1 is closest to zero than +2).I tried this...</p>
  
  <pre><code> int a[]=new int[n];
   int b[]=new int[2];
   int prev=0;
   for(int i=0;i&lt;n;a[i++]=in.nextInt());
   for(int i=0;i&lt;a.length;i++){
       for(int j=i+1;j&lt;a.length;j++){
           int sum=a[i]+a[j];
           if(prev==0)
               prev=sum;
           if(sum &gt; 0){
               if(sum &lt; prev ){
                   prev=sum;
                   b[0]=a[i];
                   b[1]=a[j];
               }
           }
           else if(sum &lt; 0){
               if(-sum &lt; prev){
                   prev=sum;
                   b[0]=a[i];
                   b[1]=a[j];
               }
           }
       }
   }
  
      Sop(b[0]+" "+b[1]);
  </code></pre>