fork download
  1.  
  2. class App {
  3. public static void main(String[] args) {
  4. String str = "HexlEt";
  5. char ch = 'e';
  6. int result = countChars(str, ch);
  7.  
  8. System.out.println("Chars quantity '" + ch + "' in a line '" + str + "': " + result);
  9. }
  10. public static int countChars(String str, char ch) {
  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 += 1;
  20. }
  21. return count;
  22. }
  23. }
  24.  
  25. // BEGIN
  26. // var i = 0;
  27. // var count = 0;
  28. // var lowerChar = Character.toLowerCase(ch);
  29. // while (i < str.length()) {
  30. // var currentChar = Character.toLowerCase(str.charAt(i));
  31. // if (currentChar == lowerChar) {
  32. // count = count + 1;
  33. // }
  34. // i = i + 1;
  35. // }
  36.  
  37. // return count;
  38. // END
Success #stdin #stdout 0.2s 58064KB
stdin
Standard input is empty
stdout
Chars quantity 'e' in a line 'HexlEt': 2