Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int countHi(String str) {
- int count = 0;
- if (str.isEmpty()){
- return 0;
- }
- if (str.length() < 2) return 0;
- if(str.charAt(0)=='h'&&str.charAt(1)=='i'){
- count= 1;
- }else {
- count=0;
- }
- return count+countHi(str.substring(1));
- }
- //countHi("xxhixx") → 1
- //countHi("xhixhix") → 2
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement