• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array question?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several questions as follows and will appreciate any one can help.

1. I need to read data from text file and strore them in an array. It is a name game from SSA. Here is the text file. I need to read them and then store in an array. The number is the ranking of the name in the 1990, 1920, 1930...
Samuel 31 41 46 60 61 71 83 61 52 35 28 Sandi 0 0 0 0 704 864 621 695 0 0 0 Sandra 0 942 606 50 6 12 11 39 94 168 257
...

I wrote the following to read the file:



But how can I create an array to store the 11 numbers?


And also I need to pass the line of text into the constructor, how can I do it? Many suggestions
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rayt Leeop wrote:
But how can I create an array to store the 11 numbers?


Object[] values = new Object[11];

Rayt Leeop wrote:
And also I need to pass the line of text into the constructor, how can I do it? Many suggestions


I am not getting you here.
frankly, clarity is missing in your description/question!
 
Rayt Leeop
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. This will create 11 number. But how can I store those number to the array since there are many data in the text file. Many thanks.




Seetharaman Venkatasamy wrote:

Rayt Leeop wrote:
But how can I create an array to store the 11 numbers?


Object[] values = new Object[11];

Rayt Leeop wrote:
And also I need to pass the line of text into the constructor, how can I do it? Many suggestions


I am not getting you here.
frankly, clarity is missing in your description/question!

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rayt Leeop wrote:This will create 11 number. But how can I store those number to the array since there are many data in the text file. Many thanks.


As I told in my previous post, still the clarity is missing! please can you explain well about your requirement?
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this. The following code creates a 2 dimensional array i.e. an array of int arrays, converts each line in the text file into an int array and adds the int array into the array of int arrays.

>
 
Rayt Leeop
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that code but the Eclipse siad Name() at the main mehtod is not type errror. Any suggestion?
I am doing a exercise similar to this: http://www.cs.utexas.edu/~scottm/cs307/Assignments/BabyNames.html

any helps? Many thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic