Question: Write a java program that has a main method called countHi with signature: public int countHiString str) In you main method call countHi at least

Write a java program that has a main method called countHi with signature: public int countHiString str)

In you main method call countHi at least 12 times to test this method with different input values. Use the 9 test cases below plus 3 additional of your choice.

For each test, compare the methods returned value to the expected value and display a message indicating whther or not the method passed the test.

Some of the code below:

/**
* Return the number of times that the string "hi" appears anywhere in the given string.
*
    *
  • countHi("abc hi ho") --> 1
  • *
  • countHi("ABChi hi") --> 2
  • *
  • countHi("hihi") --> 2
  • *
    * @param str not null string
    * @return number of times that the string "hi" appears in the given string
    */
    public static int countHi( String str )
    {
    int hiCount = 0;
    for ( int i = str.indexOf( "hi" ); i != -1; i = str.indexOf( "hi", i + 1 ) )
    {
    hiCount++;
    }
    return hiCount;
    }

    Step by Step Solution

    There are 3 Steps involved in it

    1 Expert Approved Answer
    Step: 1 Unlock blur-text-image
    Question Has Been Solved by an Expert!

    Get step-by-step solutions from verified subject matter experts

    Step: 2 Unlock
    Step: 3 Unlock

    Students Have Also Explored These Related Databases Questions!