我需要關於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"));
}
}
哦,我沒有看到我在那裏放了那樣的東西。 –