Hey guys, I need help with my homework. I'm super new to coding on my own as you can see and I need to create a character counter using an array, in just this one method.
public int[] letterCounts(String s) {
int count = 0;
int[] array= new int [27];
for(int i= 0; i < s.length(); i++){
if(s.charAt(i)>=1);{
count++;{
}
}
}
return array;
}
}
So yeah, I'm stuck and I don't know what to do next. With only this code, the test for "" comes out as a pass but tests with actual strings come out as failed because the array entries are 0. And according to my notes, apparently I need an else statement after the if and I need to implement Characters.toLowerCase for some reason. Thanks a lot guys.
Oh and here's one of the tests
@Test
public void test02() {
String s = "Baaa!";
LetterCounter lc = new LetterCounter();
int [] expected = new int[27];
expected[0] = 3;
expected[1] = 1;
expected[26] = 1;
int [] actual = lc.letterCounts(s);
String result = arraysAreTheSame(s,expected,actual);
assertTrue(result, result.length()==0);
}