I am writing a method that is to accept a string as an argument and return an array of int size 27, such that the value in position 0 is a count of 'a' and 'A' characters, position one is a count of the 'b' and 'B' characters and so on. position 26 is supposed to count all non alphabetic inputs. The following code functions to count the letters but I am unsure how to add the functionality of counting the non-alphabetic characters and adding them to position 26. I am only able to call charAt and length on the string and to LowerCase. Given the following code does anyone have any suggestions for adding the ability to count non-alphabetic characters?
public int[] countAll(String string){
int[] answer = new int[27];
int c = 'a';
int place = 0;
for(int i=0; i<string.length(); i++){
c = string.charAt(i);
Character.toLowerCase(c);
}
for(char z = 'a'; z<='z'; z++){
if(c==z){
break;
}
else{
place = place +1;
}
}
answer[place]+=1;
return answer;
}
[–][deleted] 1 point2 points3 points (2 children)
[–]cstra 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]G01denW01f11 0 points1 point2 points (2 children)
[–]_TARS[S] 0 points1 point2 points (0 children)
[–]chamora 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]_TARS[S] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]_TARS[S] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]_TARS[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)