File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Hard time filling array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hard time filling array" Watch "Hard time filling array" New topic
Author

Hard time filling array

Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
Im trying to take a read a text fille containing a coded message and put the letter into an array(alphabetically). I have spent two weeks and 5 different ways of approaching the problem but no luck. I was hoping someone could help. my text book is only good for using console.next but since it is from a file that is useless and im out of ideas. Any help would be greatly appreciated. Thanks. here is what i have so far just pretty basic.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

I have spent two weeks and 5 different ways of approaching the problem but no luck.


Could you show us some of the "5 different ways" code that you have done over the last two weeks? The code that you have shown is simply a skeleton that opens a file -- and not much else. We can't give you a hint in the right direction, if we don't know what you have attempted so far.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
Five was an exaggerationbut I have tried using the following ways


Aso using
that was nothing but errors and I even compiled a completed example from my book straight off the cd and it kept saying cannot find symbol for IntClass

And this here is the closest I have come. This code puts the first 26 letters from the text file into the array. its not alphabetically like i wanted but it was the closest i got.
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
Five was an exaggerationbut I have tried using the following ways


Aso using
that was nothing but errors and I even compiled a completed example from my book straight off the cd and it kept saying cannot find symbol for IntClass

And this here is the closest I have come. This code puts the first 26 letters from the text file into the array. its not alphabetically like i wanted but it was the closest i got.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

This code puts the first 26 letters from the text file into the array. its not alphabetically like i wanted but it was the closest i got.


Could you explain with an example what you mean by "alphabetically"? Are you saying that you want the first 26 letters of the file sorted?

Henry
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
OK here is the contents of my input file


The coded message has 49 letter in it. I want to basically pully the letters out of the input a store them alphabetically into the array. From there I need to determine the largest element and creat a shift(unknown) the print the new decoded message. I can do the rest of it but just getting the input into the array has been my downfall.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It sounds like you want 2 steps: First, put the letters into an array. Second, sort the array. For the sorting, take a look at the java.util.Arrays class.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
OK ill look. As far as putting them into the array I pieced this together searching through forums but I think that it is actually taking the letters from the file. I was hoping for your input on that.
Wentao Liang
Greenhorn

Joined: Oct 05, 2007
Posts: 13

In the preceding code,the one line code I show seems to be useless.
Is it?
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
I need that. That is why i was asking if my array is being filled with the characters of if it was just the other code I had that was putting them there but now from the file. MOre like incrementing the array I guess? All in all i still dont think the letters from the text file are being indexed to teh arrray properly. I have some code that better explains my problem.


This code was looked at by my professor and he said i was on the right track but this is the output i get right now


so i'm guessing i need some sort of coutner to increment the value of C but i'm not sure how?
Robert Mabrey
Greenhorn

Joined: Apr 02, 2008
Posts: 9
OK scratch needing a counter I think I might have it but im not sure.


And my output it
 
wood burning stoves
 
subject: Hard time filling array