我需要关于Java中的代码的帮助。Java:字符串中字符的次数
这就是问题:
示例输入:AAAAAAA
输出:A出现7.
的问题是我需要它忽略的情况。
请帮助我,我的代码工作正常,除了它不会忽略病例。
import java.io.*;
public class letter_bmp{
public static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception
{
String string1;
String pick;
String ans;
do
{
int count=0;
System.out.print("En taro Adun, Executor! Input desired string : ");
string1 = input.readLine();
System.out.print("Now, Executor...which character shall I choose : ");
pick = input.readLine();
for(int counter = 0; counter < string1.length(); counter++)
{
if(pick.charAt(0) == string1.charAt(counter))
count++;
}
System.out.print("Executor...you picked '" + pick + "' it is used " + count + " times in the word "+string1+".");
System.out.println("\nWould you like to try again, Executor? (Yes/No): ");
ans = input.readLine();
}
while(ans.equalsIgnoreCase("Yes"));
}
}
哦,我没有看到我在那里放了那样的东西。 –