Problem
How many instances of a certain character are there between the beginning of the string and a break point?
The break point is the first instance of another character.
For example, my string could be
hi, I need help! with this problem!
and I want to use a while loop to count the h s from the beginning to the !, so the output would be 2.
I am extremely new to java so I only know how to use a while loop to count up to a certain number but I don't know how to break or how to ask it to count just a certain character. Any hint in the right direction would be great.
My idea is to do something like:
while(character equals 'h', count)
else(don't count)
break if(character equals !)
print
But I don't know how to translate that to java