我几个月前就开始学习Java了,现在我有了一个作业,我必须把程序列表从a到z的所有字母表下来,旁边有数字。数字应该是字母表中的序列。这是我的代码:
String text;
int[] histg = new int[26];
int i, a = 0;
char cc;
for (i = 0; i < 26; i = i + 1){
histg[i] = 0;
System.out.println((char)(i + 'a') + ":" + histg[1]);
}
text = System.console().readLine("input text").toLowerCase();
for (i = 0; i < text.length; i = i + 1) {
cc = text.charAt(i);
histg[cc - 'a'] = histg[cc - 'a'] + 1;
}
for (i = 0; i < 26; i = i + 1){
System.out.println((char)(i + 'a') + ":" + histg[i]);
}
if ((cc >= 'a') && (cc <= 'z')) {
histg[cc - 'a'] = histg[cc - 'a'] + 1;
}
该程序应显示:
a = 1,
b = 2,
c = 3,
.....,
z = 26
但相反,我的终端不断向我显示错误:
error: cannot find symbol
for (i = 0; i < text.length; i = i + 1) {
^
symbol: variable length
location: variable text of type String
OR
程序将运行并将所有序列转换为0。
a = 0,
b = 0,
c = 0,
.....,
z = 0