-1

I need help debugging this; the problems are on lines 10-13. It says I can't convert from a String to an Int, but i don't know how to fix it. The code looks for the word "bug" within the given strings.

        public class BugHunter extends ConsoleProgram
{
    public void run()
    {
        String test1 = "Debug";
        String test2 = "bugs bunny";
        String test3 = "boogie";
        String test4 = "baby buggie";
        int index1 = findBug(test1);
        int index2 = findBug(test2);
        int index3 = findBug(test3);
        int index4 = findBug(test4);

        printBug(test1, index1);
        printBug(test2, index2);
        printBug(test3, index3);
        printBug(test4, index4);
    }

    // Returns the index of the String "bug" inside the String str
    // If str does not contain the String "bug", returns -1
    public String findBug(String str)
    {
        str.indexOf("bug");
    }

    public void printBug(String test, int index)
    {
        if(index != -1)
        {
            System.out.println(test + " has a bug at index " + index);
        }
        else
        {
            System.out.println(test + " has no bugs");
        }
    }
}
user3015822
  • 3
  • 1
  • 2
  • 1
    Possible duplicate of [Converting String to Int in Java?](http://stackoverflow.com/questions/5585779/converting-string-to-int-in-java) – ASR Aug 29 '16 at 02:23

1 Answers1

2

It appears that findBug is supposed to return the index of the word bug which is an int. So it should look something like

public int findBug(String str)
{
    return str.indexOf("bug");
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249