我一直得到錯誤 「無法找到符號 符號:變量輸入 位置:類CountNumbers」在我的程序中,我已經把它放在整個程序。找不到符號,我不知道爲什麼
import java.util.Scanner;
public class CountNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char[] chars = createArray();
System.out.println("The numbers are:");
displayArray(chars);
int [] counts = countNumbers(chars);
System.out.println();
System.out.println("The occurences of each number are:");
displayCounts(counts);
}
public static char[] createArray() {
char[] chars = new char[100];
for (int i = 0; i < chars.length; i++)
chars[i] = input.nextInt();
return chars;
}
public static void displayArray (char[] chars) {
for (int i = 0; i < chars.length; i++) {
if ((i + 1) % 20 == 0)
System.out.println(chars[i]);
else
System.out.print(chars[i] + " ");
}
}
public static int[] countNumbers(char[] chars) {
int[] counts = new int[100];
for (int i = 0; i < chars.length; i++)
counts[chars[i] - 'a']++;
return counts;
}
public static void displayCounts(int[] counts) {
for (int i = 0; i < counts.length; i++) {
if ((i + 1) % 10 == 0)
System.out.println(counts[i] + " " + (char)(i + 'a'));
else
System.out.print(counts[i] + " " + (char)(i + 'a') + " ");
}
}
}
感謝您的幫助。
你能發佈整個錯誤的堆棧跟蹤嗎? – msinghal 2014-12-05 03:21:58
使用IDE,這種類型的錯誤不會打擾你。 – 2014-12-05 03:28:28