473,500 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix a NumberFormatException error?

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. class  ShellSort
  4.  {
  5.          static void shSort(int a[])
  6.          { 
  7.            int i,k,x,width;
  8.            width=a.length/2;
  9.            while(width>=1)
  10.             {
  11.  
  12.  
  13.               for(k=width;k<a.length;k++)
  14.                 {
  15.                    x=a[k];    
  16.                    for(i=k-width;i>=0&&x<a[i];i=i-width)
  17.                        {
  18.                          a[i+width]=a[i];
  19.                        }
  20.                    a[i+width]=x;                                                
  21.                 }     
  22.               width=width/2;
  23.             }
  24.  
  25.  
  26.        }
  27.  
  28.  
  29.   public static void main(String args[])throws IOException
  30.  
  31.     {
  32.       int a[],n,i;
  33.       BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
  34.  
  35.  
  36.        System.out.println("enter number of elements");
  37.         n=Integer.parseInt(br.readLine());
  38.         a=new int[n];
  39.         System.out.println("enter elements");
  40.         for(i=0;i<n;++i)
  41.              a[i]=Integer.parseInt(br.readLine());
  42.  
  43.         shSort(a);
  44.  
  45.         System.out.println("sorted list");
  46.         for(i=0;i<n;++i)
  47.            System.out.print(a[i]+"  ");
  48.         System.out.println();
  49.      }
  50. }
Oct 28 '10 #1
1 3512
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Your code runs fine for me. Here is the output i got.

Expand|Select|Wrap|Line Numbers
  1. enter number of elements
  2. 5
  3. enter elements
  4. 6
  5. 7
  6. 8
  7. 2
  8. 1
  9. sorted list
  10. 1  2  6  7  8
How are you entering the numbers?

Regards
Dheeraj Joshi
Oct 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1049
by: nikola.bucic | last post by:
subject tell everything. tnx in advance
36
3165
by: Chuck Faranda | last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem is getting serial data back from my device. My get commands have to be sent twice for the PIC to respond properly with...
2
1931
by: qwertycat | last post by:
Is it possible to execute programs in a PHP script without waiting for the output and successfully ending the PHP script without ending the external program too?
7
2842
by: alphasahoo | last post by:
Hi I am working on a program which writes the output a SQL select statements from number of source tables first to a load matrix and then writes to a load.dat file. But while writing to the...
10
3030
by: charmeda103 | last post by:
My program keeps getting me and error and i dont why here is the error message error C2061: syntax error: identifier 'infile' error C2660: 'ReadDate' : function does not take 6 arguments...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.