2016-11-22 77 views
-1
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

你没有得到那个代码的错误,因为你没有将参数传递给'countFrequencies()',而不是'int'。 –

回答

1
  • surveyint[]
  • survey[3]int
  • countFrequencies()预计int[]参数,但得到survey[3]这是int
相关问题