나는 자바를 배우고 있는데,이 코드에 버그가있다. 나는 그것을 고치는 법을 모른다. 여기 버그 자바. 나는 그것을 고치는 방법을 모른다.
코드입니다 :public class CountLettersInArray {
public static void main(String[] args) {
char[] chars = createArray();
System.out.println("The lowercase letters are:");
displayArray(chars);
int[] counts = countLetters(chars);
System.out.println(" ");
System.out.println("The occurence of each letter are: ");
displayCounts(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.println(counts[i] + " " + (char)(i + 'a') + " ");
}
public static int[] countLetters(char[] chars) {
//Declare and create an array of 26 int
int[] counts = new int[26];
//For each lowercase letter in the array, count it
for (int i = 0; i < chars.length; i++);
counts[chars[i] - 'a']++;
return counts;
}
public static void displayArray(char[] chars) {
//Display the characters in the array 20/line
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 char[] createArray() {
//Declare the array of characters and create it
char[] chars = new char[100];
//Create lowercase characters randomly and assign them to array
for (int i = 0; i < chars.length; i++);
chars[i] = RamdomCharacter.getRandomLowerCaseLetter();
//This return the array
return chars;
}
}
내가 Eclypse로 코딩하고있어 소프트웨어는 나에게 그 두 가지를 말하고있다 : 나는이 문제를 해결하기 위해 supose하고 어떻게
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
i cannot be resolved to a variable
RamdomCharacter cannot be resolved
를?
for (int i = 0; i < counts.length; i++);
^
은 그 없애 및 {}
와 루프 시체를 둘러싸고 :
Eclipse가 말했듯이 RamdomCharacter 클래스는 존재하지 않습니다. 프로젝트에있는 경우이 클래스의 맨 위에 가져와야합니다. 그리고 각각을 위해 다음과 같이 써야합니다 : for (...) {actions; } – Kloe2378231
이클립스에서'Ctrl + Shift + F' 키를 눌러 코드가 실제로 어떻게 보이는지 볼 수있다. (예를 들어 for (')'의 뒤에'; 'RamdomCharacter'도 무엇입니까? * Ra ** n ** domCharacter *에 액세스 할 수 있습니까? – Pshemo
루프와'if/else' 구문에 중괄호 ('{'와'}')를 사용하는 방법을 배웁니다. – GriffeyDog