• HEXUS
  • HEXUS.tv
  • channel
  • gaming
  • lifestyle
  • trust
  • community
  • ESReality
  • HEXUS.community discussion forumsVisit Corsair.com

    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!

    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development

    Software and web development Databases, graphics, programming, scripting and web development.

    Reply
     
    LinkBack Thread Tools
    Old 04-05-2004, 12:35 PM   #1 (permalink)
    Senior Member
     
    Nemeliza's Avatar
     
    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);
        
    }
    
    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!

    Nemeliza is offline   Reply With Quote
    Old 04-05-2004, 12:56 PM   #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() {
    
    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
    DaBeeeenster is offline   Reply With Quote
    Old 04-05-2004, 02:13 PM   #3 (permalink)
    Senior Member
     
    Nemeliza's Avatar
     
    Join Date: Jul 2003
    Posts: 1,720
    Thanks: 1
    Thanked 5 Times in 5 Posts
    Thaaaank you!

    Appreciate it.

    Nemeliza is offline   Reply With Quote
    Old 04-05-2004, 05:41 PM   #4 (permalink)
    DsW
    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
    DsW is offline   Reply With Quote
    Reply

    Breadcrumb
    Go Back   HEXUS.community discussion forums > HEXUS.help - buying advice & technical queries > Operating systems & applications > Software and web development


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Trackbacks are On
    Pingbacks are On
    Refbacks are On


    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



    All times are GMT. The time now is 07:54 PM.

    Any representations/statements made on the HEXUS.community discussion forums are the representations/statements of the author i.e. the person/organisation making them. If any such representations/statements are disputed they are a matter between the parties concerned.
    HEXUS Limited accepts no responsibility for any misrepresentations, inaccurate or false statements made by any person/organisation other than HEXUS Limited employees.
    For more information please read HEXUS Limited's terms, conditions and privacy policy.

    Hosted Exchange

    Powered by vBulletin® Version 3.8.4
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Content Relevant URLs by vBSEO 3.3.2
    © Copyright 2009 HEXUS® Limited. All rights reserved. Unauthorised reproduction strictly prohibited.