This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes array question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "array question?" Watch "array question?" New topic
Author

array question?

Rayt Leeop
Greenhorn

Joined: Jun 09, 2011
Posts: 23
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
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jun 09, 2011
Posts: 23
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

Joined: Jan 28, 2008
Posts: 5575

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?
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
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

Joined: Jun 09, 2011
Posts: 23
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array question?