Java Function to Calculate Statistical Mode

Tuesday January 10, 2006

I looked everywhere on the web to find a java function to calculate the mode of an array of primitive ints. This will work for floats and long ints too, I suppose.

Anyway, since it was impossible to find, I figured I would post it here so maybe someone else can benefit.

public int calcMode(int[] sourceArray) {
	int mode = 0;	    
	Arrays.sort(sourceArray);	
	int[] valCounts = new int[(sourceArray.length-1)];
	for(int val:sourceArray) valCounts[val]++;
	int i = 0;			
	while(i < valCounts.length) {
		if(valCounts[i] >= valCounts[mode]) mode = i;
		i++;
	}
	return mode;
}

Hope this helps someone!

comments 2 Comments | days old 4716 days old | Direct Link

Free AJAX Calendar

Thursday December 22, 2005

Well, here it is. My first project using AJAX. I'm very familiar with javascript, so using the AJAX methodology came very natural to me. I made this php calendar script for a customer a few months back, but it required page refreshes to load the next and previous months.

When I heard about AJAX, the calendar seemed to be a perfect project to implement using it. I've tested it in the most recent browsers, Firefox and IE 6, and both work perfectly. Enjoy!

Click here

comments 2 Comments | days old 4736 days old | Direct Link

New Java Game - Battleship

Wednesday December 21, 2005

I recently started a new job as a java application developer, so I figured writing a game would be a great learning experience. I finished it up this week, so I wanted to put it out there for you to download. Click the link below to download the zip file. Just extract the exe and run it. Let me know what you think.

Click here to download the file

comments 2 Comments | days old 4737 days old | Direct Link