You are viewing our Forum Archives. To view or take place in current topics click here.
Can someone help me with this String question
Posted:

Can someone help me with this String questionPosted:

Dxminic
  • TTG Master
Status: Offline
Joined: Mar 16, 201014Year Member
Posts: 866
Reputation Power: 138
Status: Offline
Joined: Mar 16, 201014Year Member
Posts: 866
Reputation Power: 138
So please dont give me the answer more or less guide me in the right direction.

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

This is what I have so far



public int countHi(String str)
{
  for (int i=0; i < str.length()-1; i++)
}




All I need is a push in the right direction.

Thanks

The following 2 users thanked Dxminic for this useful post:

SWR (11-08-2016), Xbox (11-07-2016)
#2. Posted:
-Deano
  • PC Master Race
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
You will search through the string until you find 'h', if you find one, check the next character for 'i'.

If it matches, increase your count of "hi"s appearing.
If it doesn't match, continue your search of the string.

Be aware for things that may catch your program out such as "hhi", "Hi", etc.#

If you need any further tips, reply or send me a PM.
#3. Posted:
Dxminic
  • TTG Master
Status: Offline
Joined: Mar 16, 201014Year Member
Posts: 866
Reputation Power: 138
Status: Offline
Joined: Mar 16, 201014Year Member
Posts: 866
Reputation Power: 138
-Deano wrote You will search through the string until you find 'h', if you find one, check the next character for 'i'.

If it matches, increase your count of "hi"s appearing.
If it doesn't match, continue your search of the string.

Be aware for things that may catch your program out such as "hhi", "Hi", etc.#

If you need any further tips, reply or send me a PM.


Thanks man

[ Register or Signin to view external links. ]
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.