class App {
public static void main
(String[] args
) { char ch = 'e';
int result = countChars(str, ch);
System.
out.
println("Chars quantity '" + ch
+ "' in a line '" + str
+ "': " + result
); }
public static int countChars
(String str,
char ch
) { var i = 0;
var count = 0;
while (i < str.length()) {
var currentChar
= Character.
toLowerCase(str.
charAt(i
)); if (currentChar == lowerChar) {
count = count + 1;
}
i += 1;
}
return count;
}
}
// BEGIN
// var i = 0;
// var count = 0;
// var lowerChar = Character.toLowerCase(ch);
// while (i < str.length()) {
// var currentChar = Character.toLowerCase(str.charAt(i));
// if (currentChar == lowerChar) {
// count = count + 1;
// }
// i = i + 1;
// }
// return count;
// END
IAogY2xhc3MgQXBwIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIFN0cmluZyBzdHIgPSAiSGV4bEV0IjsKICAgIGNoYXIgY2ggPSAnZSc7CiAgICBpbnQgcmVzdWx0ID0gY291bnRDaGFycyhzdHIsIGNoKTsKIAogICAgU3lzdGVtLm91dC5wcmludGxuKCJDaGFycyBxdWFudGl0eSAnIiArIGNoICsgIicgaW4gYSBsaW5lICciICsgc3RyICsgIic6ICIgKyByZXN1bHQpOwogfQogICAgcHVibGljIHN0YXRpYyBpbnQgY291bnRDaGFycyhTdHJpbmcgc3RyLCBjaGFyIGNoKSB7CiAgICAgICAgdmFyIGkgPSAwOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIGxvd2VyQ2hhciA9IENoYXJhY3Rlci50b0xvd2VyQ2FzZShjaCk7CiAgICAgICAgd2hpbGUgKGkgPCBzdHIubGVuZ3RoKCkpIHsKICAgICAgICAJdmFyIGN1cnJlbnRDaGFyID0gQ2hhcmFjdGVyLnRvTG93ZXJDYXNlKHN0ci5jaGFyQXQoaSkpOwogICAgICAgICAgICBpZiAoY3VycmVudENoYXIgPT0gbG93ZXJDaGFyKSB7CiAgICAgICAgICAgICAgICBjb3VudCA9IGNvdW50ICsgMTsKICAgICAgICB9CiAgICAgICAgICAgIGkgKz0gMTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgfQp9CgogLy8gQkVHSU4KICAgIC8vICAgIHZhciBpID0gMDsKICAgIC8vICAgIHZhciBjb3VudCA9IDA7CiAgICAgLy8gICB2YXIgbG93ZXJDaGFyID0gQ2hhcmFjdGVyLnRvTG93ZXJDYXNlKGNoKTsKICAgICAvLyAgIHdoaWxlIChpIDwgc3RyLmxlbmd0aCgpKSB7CiAgICAgLy8gICAgICAgdmFyIGN1cnJlbnRDaGFyID0gQ2hhcmFjdGVyLnRvTG93ZXJDYXNlKHN0ci5jaGFyQXQoaSkpOwogICAgIC8vICAgICAgIGlmIChjdXJyZW50Q2hhciA9PSBsb3dlckNoYXIpIHsKICAgIC8vICAgICAgICAgICAgY291bnQgPSBjb3VudCArIDE7CiAgICAgLy8gICAgICAgfQogICAgIC8vICAgICAgIGkgPSBpICsgMTsKICAgICAvLyAgIH0KCiAgICAgLy8gICByZXR1cm4gY291bnQ7CiAgICAgICAgLy8gRU5E