|
-
February 8th, 2011, 08:40 PM
#1
Counting Letters using Arrays
This is Homework so writing out the answer would be unacceptable.
Anyways, The objective is to write a method that will pass a set of test in which it counts the Letters in the test. I have little to no idea what to do and what I got is from messy notes. My professor says that we can us a "helper method" called isLetter. However I do not know how I would define this method in which it would "check" to see if the statements in the test have a certain letter. The reason the size of the array is 27 is because not only does it include the alphabet, but it also include a symbol. Thanks ahead of time.
public int[] letterCounts(String s) {
int[] counts = new int[27];
for (int i= 0; i < s.length(); ){
if(isLetter(s.charAt(i))){
counts[i - 'a']++;
}
else{
}
counts[26]++;
}
return counts;
}
private boolean isLetter(char c){
return true;
}
}
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
|