fork download
  1. class App {
  2. public static void main(String[] args) {
  3. String str = "HexlEt";
  4. char ch = 'e';
  5. int result = countChars(str, ch);
  6. System.out.println("Chars quantity '" + ch + "' in a line '" + str + "': " + result);
  7. }
  8.  
  9. public static int countChars(String str, char ch) {
  10. // BEGIN
  11. var i = 0;
  12. var count = 0;
  13. var lowerChar = Character.toLowerCase(ch);
  14. while (i < str.length()) {
  15. var currentChar = Character.toLowerCase(str.charAt(i));
  16. if (currentChar == lowerChar) {
  17. count = count + 1;
  18. }
  19. i = i + 1;
  20. }
  21.  
  22. return count;
  23. // END
  24. }
  25. }
Success #stdin #stdout 0.18s 57988KB
stdin
Standard input is empty
stdout
Chars quantity 'e' in a line 'HexlEt': 2