I am trying to create a method but am having difficulty, here is what i have:
This is the main.
This is the getMode method:Code:public static void main(java.lang.String[] args) { for (int i = 0; i < 50; i++) { int rand = (int) Math.ceil(Math.random() * 100); num[i] = rand; } for (int i = 0; i < 50; i++) { System.out.println(num[i]); } calcMode.getMode(num); System.out.println(calcMode); }
When i run it i amgetting this error:Code:public static int getMode() { int j = 0; int[] counters = new int[100]; //count the occurrence of each number for (int i = 0; i < num.length; ++i){ ++counters[num[i]]; //count the frequency of particular number } //find mode from range array mode = 0; for (int i = 0; i < counters.length; ++i){ if (counters[i] > counters[mode]){ mode = i; //new mode index } } //find if multiple modes int maxNum = counters[mode]; for (j = 0; j < counters.length; ++j){ if (counters[j] == maxNum){ System.out.println("mode : " + j); } } return j; }
HEEEEEEEEEEEEEEELP!Code:The method getMode invoked for type int with arguments (int []) is not defined![]()


LinkBack URL
About LinkBacks

Reply With Quote