我需要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"));
    }

}

最佳答案

使用String.toLowerCase()方法将字符串转换为小写字符。

// ...
string1 = input.readLine().toLowerCase();
// ...
pick = input.readLine().toLowerCase();
// ...

09-10 08:23
查看更多