|
-
Apr 22nd, 2004, 10:33 AM
#1
Thread Starter
New Member
help
i need a string of sentences to pass to a method along with an array of letters from ?a? to ?z?. The method steps through each string and determines the number of a?s, b?s, c?s, ?, z?s in each line and in the paragraph in total. im new with java so any help is appreciated.
-
Apr 22nd, 2004, 12:21 PM
#2
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 25th, 2004, 06:29 PM
#3
Addicted Member
Use a StringTokenizer object to parse the String and create an array of integers that keeps track of the amount of times each letter occurs.
eg:
Code:
private int[] countArray = new int[26];
private char[] characters = new char[26];
private int[] parse ( String S ) {
StringTokenizer ST = new StringTokenizer ( S );
while ( ST.hasMoreTokens () ) {
String next = ST.nextToken ();
char[] c = next.toCharArray ();
for ( int i = 0; i < c.length; i ++ ) {
System.out.println ( c[i] );
if ( isInCharacters ( c[i] ) {
int position = positionOfCharacter ( c[i] );
countArray[position] ++;
}
}
}
}
The isInCharacters ( char a ) method would sweep through the characters array and check to see if the character you just passed into it is there.
Hope this helps!
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|