字符查找与统计
请修改编辑器中的代码,完成以下功能: 在一个字符数组中查找指定的字符,然后将该字符在数组中出现过的所有位置以及出现的次数输出。 程序的运行结果如下。 Found A at index 0 Found A at index 2 The total amount of A is 2 输出示例: Found A at index 0 Found A at index 2 The total amount of A is 2
public class Main {
public static void main(String[] args) {
//**********found**********
_________ arrayOfChars = { 'A', 'B', 'A','D', 'E','F','G' };
char searchfor = 'A';
int i=0, j=0;
//**********found**********
while ( i < arrayOfChars.__________) {
if (arrayOfChars[i] == searchfor) {
System.out.println("Found " + searchfor + " at index " + i);
j++;
}
//**********found**********
________________ ;
}
//**********found**********
if (_______) {
System.out.println("The total amount of " + searchfor + " is " + j );
} else {
System.out.println(searchfor + " is not in the array");
}
}
}控制台
调试终端
