![]() | ![]() |
|
Welcome to the HEXUS.community discussion forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and other features. By joining our free community you will have access to post topics, respond to polls and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! |
| |||||||
| Software and web development Databases, graphics, programming, scripting and web development. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member Join Date: Jul 2003
Posts: 1,720
Thanks: 1
Thanked 5 Times in 5 Posts
| Java METHOD help, UEGENT*** I am trying to create a method but am having difficulty, here is what i have: This is the main. 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);
}
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;
}
Code: The method getMode invoked for type int with arguments (int []) is not defined |
| | |
| | #2 (permalink) |
| Goat Boy Join Date: Jul 2003 Location: Alexandra Park, London
Posts: 2,422
Thanks: 0
Thanked 0 Times in 0 Posts
| When you define getMode you are telling it to RETURN an int, not receive one. So instead of: Code: public static int getMode() {
Code: public static int getMode(int whatEverYouWantToCallTheIntegerYouPassIn) {
|
| | |
| | #4 (permalink) |
| Senior Member Join Date: Aug 2003 Location: Glasgow
Posts: 292
Thanks: 0
Thanked 0 Times in 0 Posts
| By the way - the Random() class is worth a look for generating random numbers. e.g. rather than doing Code: int rand = (int) Math.ceil(Math.random() * 100); Code: int rand = (new Random()).nextInt(100); dave |
| | |
![]() |
| Breadcrumb | ||||||
| ||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java Problems | Applecrusher | Operating systems & applications | 4 | 27-04-2004 12:12 PM |
| Uploading Java games to mobiles | Bunjiweb | General discussion | 20 | 30-12-2003 06:07 PM |
| Java | Jonny M | Software and web development | 8 | 24-12-2003 01:33 PM |
| Running rmid from a java prog | killgORE | distributed computing | 1 | 02-12-2003 05:46 PM |
| Java vs .NET | DaBeeeenster | Software and web development | 2 | 11-09-2003 01:47 PM |