DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help

Threaded View

  1. #1
    Join Date
    Dec 2005
    Posts
    27

    Help

    Can anyone give me some ideas for calculating the mode of an array of doubles. I am looking for an alogorithm not code. Thank you for any help
    This is what i have so far
    Code:
    public static double mode(double array[]) throws IOException
        {
            double n;
            int freq = 0;
            int Mfreq = 0;
            double Mn = array[0];
            ArrayList modes = new ArrayList(1); 
            modes.add(1.0); 
            PrintStream fout = new PrintStream( new FileOutputStream("output.txt"));
            for (int i = 0; i < array.length; i++) 
            {
                n = array[i];
                fout.println("n = "+n); 
                for (int j = 0; j < array.length; j++) 
                {
                    fout.println("\tarray["+j+"] = "+array[j]); 
                    if (array[j] == n) 
                    {
                        fout.println("\t\t Freq ++"); 
                        freq++;
                        double temp = (Double) modes.get(modes.size()-1); 
                        if(temp <= freq)
                        {
                            modes.add(array[j]);
                        }
                    }
                    
                    
                }
                fout.println("Freq = "+freq); 
                freq = 0;
                if (freq > Mfreq) 
                {
                    Mn = n;
                }
            }
            fout.print("\t\tArrayList Modes"); 
            for(int i = 0; i <= modes.size() -1; i ++)
            {
                fout.println(modes.get(i));    
            }
        return Mn;
        }
    I used the file output to help debug
    Last edited by stormswimmer; 02-16-2006 at 05:37 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links