Java recursion Index out of range 1

I am currently trying to figure out why the cases that end with x results in an OutOfBoundsError like the 3 test cases below. The assignment is to count the number of ‘x’ in a string; if an ‘x’ is follow by another ‘x’ counted as double. Thank you, and I would very grateful if… Read More Java recursion Index out of range 1

StringIndexOutOfBoundsException when trying to count 'a's in the entered word in Java

public class methods { public static int howMany(String word) { char character = ‘a’; int a = 0; for (int i=0;i<=word.length();i++) { if (word.charAt(i)==character) { a++; } } return a; } public static void main(String[] args) { System.out.println(howMany("afdfaf")); } } code gives error. please help. I couldn’t find where is the error. Expected output: 2… Read More StringIndexOutOfBoundsException when trying to count 'a's in the entered word in Java