【发布时间】:2019-06-14 10:25:48
【问题描述】:
练习:创建一个计算出现次数的方法,并将字符作为输入。 出现次数最多的字符被替换为进入方法的字符(new char)
public void myMethod() {
String text = "ovolollo";
int numberOfLetterA = ProvaEsercizio9.countCharOccurrences(text, 'a');
ecc..
System.out.println("Lettera a = " + numberOfLetterA);
ecc..
}
public static int countCharOccurrences(String source, char target) {
int counter = 0;
for (int i = 0; i < source.length(); i++) {
if (source.charAt(i) == target) {
counter++;
}
}
return counter;
}
【问题讨论】:
-
这似乎是对您的练习,而不是对我们而言。真正的问题是什么?
-
你有什么问题?
-
您好,stackoverflow 不是提供练习的网站,而是提供帮助的,如果您在工作中遇到问题,您可以告诉您尝试了什么,不明白什么。
标签: java arrays string char int