I figured out how to count the occurrence of all the strings expect one of them because I am using indexOf because I haven't learned anything new in this class that I'm taking so I was wondering if I can get help here is the code. (Not able to count the Bolded "cat")
class Main {
public static void main(String[] args) {
String[] arr= {"Catcat", "Dogsaregoodcatsarebetter", "Ilovecatcat", "Goatsarecutetoo"};
System.out.println(countOccurence2(arr, "cat"));
System.out.println(countOccurence2(arr, "cute"));
System.out.println(countOccurence2(arr, "horse"));
}
public static int countOccurence2(String[]arr, String n)
{
int count = 0;
for(int i = 0; i < arr.length; i++)
{
if(arr[i].indexOf(n) != -1)
{
count++;
}
}
return count;
}
}