Results 1 to 4 of 4

Thread: Java METHOD help, UEGENT***

  1. #1
    Senior Member Nemeliza's Avatar
    Join Date
    Jul 2003
    Posts
    1,719
    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);
        
    }
    This is the getMode method:
    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;	
    
    }
    When i run it i amgetting this error:
    Code:
    The method getMode invoked for type int with arguments (int []) is not defined
    HEEEEEEEEEEEEEEELP!

  2. #2
    Goat Boy
    Join Date
    Jul 2003
    Location
    Alexandra Park, London
    Posts
    2,428
    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() {
    you should have

    Code:
    public static int getMode(int whatEverYouWantToCallTheIntegerYouPassIn) {
    I'm not sure what the method is meant to do, but that is why it is not compiling.
    "All our beliefs are being challenged now, and rightfully so, they're stupid." - Bill Hicks

  3. #3
    Senior Member Nemeliza's Avatar
    Join Date
    Jul 2003
    Posts
    1,719
    Thanks
    1
    Thanked
    5 times in 5 posts
    Thaaaank you!

    Appreciate it.

  4. #4
    DsW
    DsW is offline
    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);
    you can do

    Code:
    int rand = (new Random()).nextInt(100);
    cheers,
    dave

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java Problems
    By Applecrusher in forum Software
    Replies: 4
    Last Post: 27-04-2004, 01:12 PM
  2. Uploading Java games to mobiles
    By Bunjiweb in forum General Discussion
    Replies: 20
    Last Post: 30-12-2003, 07:07 PM
  3. Java
    By Jonny M in forum Software
    Replies: 8
    Last Post: 24-12-2003, 02:33 PM
  4. Running rmid from a java prog
    By killgORE in forum Software
    Replies: 1
    Last Post: 02-12-2003, 06:46 PM
  5. Java vs .NET
    By DaBeeeenster in forum Software
    Replies: 2
    Last Post: 11-09-2003, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •