I'm stuck, and having a bump in my program, here is a little snippet of the contructor just ot give you an idea.
To Sum it up - I am running the letterCount to take in a string set by the client. It will take that string, and tally how many occurences of each letter occurs within that string inside an array of 26 (26 letter in alphabet).
0 = A
1 = B
2 = C
etc etc.
If the client passed a string of "AAAB", then the array would have the value 3 in index 0.
So The main issue lies within the 2nd code i posted, my toString method. I am required to have the toString method return a string representation of my letterCount object.
For example, using my example above, index[0] will have value of 3 - because we stored 3 letter 'a's previously, and index[1] would have had 1.
I need the toString method.. to somehow.. take those values and output it back out again? and return it as a string? I've been only able to list them back out as println's and i'm quite stumped on how to put it back together as a single string..
The expected string should produce :
[aaab]
So my question is - I kind of need pointers or help on how I can, instead of printing values one after another, just return a full single string representations.
PHP Code:
private int[] letterData;
public LetterCount(String data){
letterData = new int[26];
sizeCount = 0;
String s = data;
s = s.toLowerCase();
for( int i = 0; i < 26Y; i++){
char result = (char) ('a' + i);
for(int x= 0; x < s.length(); x++) {
if(s.charAt(x) == result){
letterData[i]++;
sizeCount++;
}
}
}
I am having issues with this method, I know I'm not doing it right..
PHP Code:
public String toString(){
for( int y = 0; y < 26; y++){
for( int w = 0; w < letterData[y] ; w++){
System.out.print((char)('a'+y));
}
}