korobushk

countHi

Apr 20th, 2021
559
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×