Advertisement
korobushk

countHi

Apr 20th, 2021
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. public int countHi(String str) {
  2.     int count = 0;
  3.   if (str.isEmpty()){
  4.     return 0;
  5.   }
  6.    if (str.length() < 2) return 0;
  7.  
  8.   if(str.charAt(0)=='h'&&str.charAt(1)=='i'){
  9.     count= 1;
  10.   }else {
  11.   count=0;
  12.   }
  13.   return count+countHi(str.substring(1));
  14. }
  15.  
  16. //countHi("xxhixx") → 1
  17. //countHi("xhixhix") → 2
  18. //
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement