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. | |
| * | |
| * | |
| * | |
| * | |
| * | |
| * @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
Get step-by-step solutions from verified subject matter experts
