Guest User

Untitled

a guest
Jan 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class countx{
  2.  
  3. public static void main(String[] argv){
  4. System.out.println(countX("xxhixx"));
  5. System.out.println(countX("xhixhix"));
  6. }
  7.  
  8. public static int countX(String str) {
  9. if(str.length()==1){
  10. if(str.equals("x"))
  11. return 1;
  12. else
  13. return 0;
  14. }else if(str.length()>1){
  15. if(str.charAt(0)=='x')
  16. return 1+countX(str.substring(1));
  17. else
  18. return countX(str.substring(1));
  19. }else{
  20. return 0;
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment