-
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.
-
-
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!