How to fix a NumberFormatException error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronak U

    How to fix a NumberFormatException error?

    Code:
    import java.io.*;
    
    class  ShellSort
     {
             static void shSort(int a[])
             { 
               int i,k,x,width;
               width=a.length/2;
               while(width>=1)
                {
                        
                    
                  for(k=width;k<a.length;k++)
                    {
                       x=a[k];	
                       for(i=k-width;i>=0&&x<a[i];i=i-width)
                           {
                             a[i+width]=a[i];
                           }
                       a[i+width]=x;                                                
                    }     
                  width=width/2;
                }
    
    
           }
    
    
      public static void main(String args[])throws IOException
    
        {
          int a[],n,i;
          BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
     
      
           System.out.println("enter number of elements");
            n=Integer.parseInt(br.readLine());
            a=new int[n];
            System.out.println("enter elements");
            for(i=0;i<n;++i)
                 a[i]=Integer.parseInt(br.readLine());
    
            shSort(a);
    
            System.out.println("sorted list");
            for(i=0;i<n;++i)
               System.out.print(a[i]+"  ");
            System.out.println();
         }
    }
    Last edited by MMcCarthy; Oct 28 '10, 09:54 AM. Reason: added code tags
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Your code runs fine for me. Here is the output i got.

    Code:
    enter number of elements
    5
    enter elements
    6
    7
    8
    2
    1
    sorted list
    1  2  6  7  8
    How are you entering the numbers?

    Regards
    Dheeraj Joshi

    Comment

    Working...