fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int countLetter(char letter, String texto)
  11. {
  12. if (texto.length() == 0) return 0;
  13. if (texto.charAt(0) == letter)
  14. return 1 + countLetter(letter, texto.substring(1));
  15. return countLetter(letter, texto.substring(1));
  16. }
  17.  
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. char letter = 'a';
  21. String texto = "Programação";
  22. System.out.println(countLetter(letter, texto));
  23. }
  24. }
Success #stdin #stdout 0.03s 4386816KB
stdin
Standard input is empty
stdout
2