|
-
February 8th, 2011, 08:53 PM
#2
Re: Counting Letters using Arrays
If you cast a character as an integer, that character's ascii value will be returned. Uppercase letters have ascii values between 65 and 90 and lowercase letters have ascii values between 97 and 122.
A more complete ascii table can be found here: http://www.asciitable.com/
You may be able to use this in your helper isLetter() method.
Also there are a couple things about the code you posted:
Code:
for (int i= 0; i < s.length(); ){
if(isLetter(s.charAt(i))){
counts[i - 'a']++; /* the 'i' here refers to an index into the String, not the character itself */
}
else{
} /* your braces seem to mess up starting here */
counts[26]++;
}
return counts;
}
Last edited by bgroves85; February 8th, 2011 at 09:25 PM.
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
|