Find all occurrences of the word “the” without using regex

Posted on

Problem

I have an assignment to find all occurrences of the word “the” without using regex:

Use the indexOf method to do this. The word “the” could also appear in a larger word, such as “Theresa” or “other”.

Please confirm if this is the best way to do that.

import java.util.Scanner;

public class TheFinder
{
public static void main(String[] args)
{
int theCounter;
int indexOfThe = 0;

Scanner input = new Scanner(System.in);
System.out.print("Enter a sentence with a word "the"" or type ""quit"" to quit: "");

Solution

Leave a Reply

Your email address will not be published. Required fields are marked *