im creating a program called "Book" for school and im having alot of trouble. IM suppost to find out how many times the character "a" comes up in a txt file. The txt file reads the following "go to the bathroom he said and he was right I needed to go to the bathroom" . Here is my code but it doesnt seem to work at all and i am stuck.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Book
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner text = new Scanner (new File("data.txt"));
String word = null;
int count = 0;
while(text.hasNextLine())
{
word = text.nextLine();
for (int i = 0; i < word.length(); i++)
{
if (word.substring(i) == "a")
{
count++;
}
}
}
System.out.print(count);
}
}