public class Survey
{
public static void main(String[] args)
{
int[] survey = {1,2,6,4,8,5,9,7,8,10,1,6,3,8,6,10,3,8,2,7,6,5,7,6,8,6,7,5,6,6,5,6,7,5,6,4,8,6,8,10};
int length = survey.length;
int undivided = 0, avg;
for(int loop = length -1; loop>=0; loop--)
{
int add = survey[loop];
System.out.println(add);
undivided = add + undivided;
}
System.out.println(undivided);
avg = (undivided/length);
System.out.println("The average score for the cafeteria was:" + avg);
System.out.println(countFrequencies(survey[3]));
}
public static void countFrequencies(int input[]) {
int n = input.length;
for (int i = 0; i < n; i++) {
input[i]--;
}
for (int i = 0; i < n; i++) {
input[input[i] % n] += n;
}
for (int i = 0; i < n; i++) {
System.out.println((i + 1) + " " + input[i] / n);
input[i] = input[i] % n + 1;
}
}
}
如何输入频率方法......它不起作用。我不知道我还能尝试什么,但当我尝试输入任何内容时,它似乎有点问题。它不会正常运行。
错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method countFrequencies(int[]) in the type Survey is not applicable for the arguments (int)
at Survey.main(Survey.java:18)
答案 0 :(得分:1)
survey
是int[]
survey[3]
是int
countFrequencies()
需要int[]
参数,但获得survey[3]
int