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
) { // BEGIN
var i = 0;
var count = 0;
while (i < str.length()) {
var currentChar
= Character.
toLowerCase(str.
charAt(i
)); if (currentChar == lowerChar) {
count = count + 1;
}
i = i + 1;
}
return count;
// END
}
}
Y2xhc3MgQXBwIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgIFN0cmluZyBzdHIgPSAiSGV4bEV0IjsKICAgIGNoYXIgY2ggPSAnZSc7CiAgICBpbnQgcmVzdWx0ID0gY291bnRDaGFycyhzdHIsIGNoKTsKICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQ2hhcnMgcXVhbnRpdHkgJyIgKyBjaCArICInIGluIGEgbGluZSAnIiArIHN0ciArICInOiAiICsgcmVzdWx0KTsKfQogICAgCiAgICBwdWJsaWMgc3RhdGljIGludCBjb3VudENoYXJzKFN0cmluZyBzdHIsIGNoYXIgY2gpIHsKICAgICAgICAvLyBCRUdJTgogICAgICAgIHZhciBpID0gMDsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBsb3dlckNoYXIgPSBDaGFyYWN0ZXIudG9Mb3dlckNhc2UoY2gpOwogICAgICAgIHdoaWxlIChpIDwgc3RyLmxlbmd0aCgpKSB7CiAgICAgICAgICAgIHZhciBjdXJyZW50Q2hhciA9IENoYXJhY3Rlci50b0xvd2VyQ2FzZShzdHIuY2hhckF0KGkpKTsKICAgICAgICAgICAgaWYgKGN1cnJlbnRDaGFyID09IGxvd2VyQ2hhcikgewogICAgICAgICAgICAgICAgY291bnQgPSBjb3VudCArIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaSA9IGkgKyAxOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgICAgIC8vIEVORAogICAgfQp9