开关函数中的字符串到字符,java

开关函数中的字符串到字符,java,java,types,Java,Types,我是编程新手,我正在尝试编写一个句子频率分析代码。我有一个问题,在switch语句中它是char,在case中它是string,不能一起工作。对于字母表中的每个字母,我都有一个int变量,我想对每个字母做一个大小写,这样就可以计算出来。有人能帮我在这两种语言中创建相同的变量类型吗 for (int index = 0; index <= text.length();index++) { switch (text.charAt(index)) { c

我是编程新手,我正在尝试编写一个句子频率分析代码。我有一个问题,在switch语句中它是char,在case中它是string,不能一起工作。对于字母表中的每个字母,我都有一个int变量,我想对每个字母做一个大小写,这样就可以计算出来。有人能帮我在这两种语言中创建相同的变量类型吗

    for (int index = 0; index <= text.length();index++) {
        switch (text.charAt(index)) {

        case "a" : acount++;break;

        }
    }

字符必须用单引号括起来,字符串必须用双引号括起来。也要交互,直到小于文本长度

for (int index = 0; index < text.length();index++) {

      switch (text.charAt(index)) {

      case 'a' : acount++;break;

      }
  }

请尝试大小写“a”,而不是大小写aAlso indexfor (int i = 0; i <= text.length(); i++) { switch (Character.toLowerCase(text.charAt(i))) { case 'a': acountA++; break; case 'b': acountB++; break; default: break; } }