My instruction for this was to write a program that prompts the user to enter a string and count the number of occurrences of the word: fox. it always comes up with the error
Main.java:23: error: bad operand types for binary operator '=='
if (str.charAt(i) == a)
^
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter a string: ");
String str = input.nextLine();
System.out.println("Enter a word: ");
String a = input.nextLine();
int letterCheck = count(str, a);
System.out.println("The word " + a + "appeared" + letterCheck + "times in" + str);
}
public static int count(String str, String a)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if (str.charAt(i) == a)
{
count++;
}
}
return count;
}
}