Java for循环出错-尝试使用循环计数字母的重复次数

Java for循环出错-尝试使用循环计数字母的重复次数,java,string,compiler-errors,applet,Java,String,Compiler Errors,Applet,在for循环中,Java小程序显示我有一个错误。我试图使用for循环来计算字母的重复次数 String countString = ""; for (int i = 0; i < 26; i++){ // at the line below, my java applet says I have an error, and that the //"letterCounts" should be a int and not a string, but I need it to be a s

在for循环中,Java小程序显示我有一个错误。我试图使用for循环来计算字母的重复次数

String countString = "";
for (int i = 0; i < 26; i++){
// at the line below, my java applet says I have an error, and that the 
//"letterCounts" should be a int and not a string, but I need it to be a string
     String n = letterCounts[i];
     if (n.equals("0")) {
          countString = countString + "   ";
     } else if (n.length() == 1) {
          countString = countString + " " + n + " ";
     } else {
          countString = countString + n + " ";
     }
} 
this.countLabel.setText(countString);
String countString=”“;
对于(int i=0;i<26;i++){
//在下面的一行,我的java小程序说我有一个错误,并且
//“letterCounts”应该是int而不是字符串,但我需要它是字符串
字符串n=字母计数[i];
如果(n等于(“0”)){
countString=countString+“”;
}else if(n.length()==1){
countString=countString+“”+n+“”;
}否则{
countString=countString+n+“”;
}
} 
this.countLabel.setText(countString);

您没有显示
字母计数的定义,但我打赌它是
int[]字母计数

因此,由于
letterCounts
是一个
int
数组,因此不能将其分配给
字符串

只需将
stringn
更改为
intn
,并与
n==0进行比较,就可以了。见下文:

    String countString = "";

    for (int i = 0; i < 26; i++)
    {
      int n = letterCounts[i];

      if (n == 0) {
        countString = countString + "   ";
      } else if (n < 10) {
        countString = countString + " " + n + " ";
      } else {
        countString = countString + n + " ";
      }
    } 

    this.countLabel.setText(countString);
String countString=”“;
对于(int i=0;i<26;i++)
{
int n=字母计数[i];
如果(n==0){
countString=countString+“”;
}否则如果(n<10){
countString=countString+“”+n+“”;
}否则{
countString=countString+n+“”;
}
} 
this.countLabel.setText(countString);

这不是JS,Java和JS就像一辆汽车和一幅卡通画一样-\uz-没有意识到两者都被标记了。你能给出字母计数的定义吗?为了更快地获得更好的帮助,发布一个or。了解你收到的错误也会很有用-请将它放在帖子中。