Eclipse, Maya, Project Euler

Eclipse and Maya

I am currently stumped with connecting the Eclipse Maya Editor on my macbook. It always shows a “Bad version number in .class file” error, that’s why the Maya Editor Prefs Page throws a NoClassDefFoundError whenever I load Eclipse. I tried checking the jar file which was unhelpful because it was producing “non-human readable” ASCII characters. I also changed my Java Preferences to version 1.6 which caused the JVM on Eclipse to crash after I rebooted my macbook. I am hoping I could make this work without installing Bootcamp so I won’t waste my time installing Windows 7 (and Maya later on). I’ll try looking for other solutions on the forums but it seems that installing Bootcamp is an optimal solution right now.

Eclipse and Project Euler

Anywhoo, I decided to take a break on working with Maya and try to do a little bit of coding in Java. I am solving some of the problems on ProjectEuler even though I haven’t done much. My goal for doing this is to develop my logical thinking and to come up with efficient algorithms in the long run. I will be using Eclipse as my IDE for the exercises so it should be fun! Yaay!

Problem 1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

In Java…

public class NatNumMult35 {

	/*
	 *If we list all the natural numbers below 10 that are multiples of 3 or 5,
	 *we get 3, 5, 6 and 9. The sum of these multiples is 23.
	 *
	 *Find the sum of all the multiples of 3 or 5 below 1000.
	 *
	 */

	private int num;
	private int sumMult=0;
	public NatNumMult35(int num) {
		this.num = num;
		sumMult = this.sumOfMultiples(this.getMultiplesOfThreeAndFive(num));
	}

	public int[] getMultiplesOfThreeAndFive(int num){
		int[] multThreeAndFive = new int[2];

		multThreeAndFive[0] = (num-1)/3;
		//Determines how many multiples of 3 in a given number;

		multThreeAndFive[1] = (num-1)/5;
		//Determines how many multiples of 5 in a given number;

		return multThreeAndFive;
	}

	public int sumOfMultiples(int[] temp){
		int sum=0;

		for(int i=1; i = temp[0]; i++){
                   // Adds up multiples of 3; 
	           sum+=(3*i);
		}

		for(int i=1; i = temp[1]; i++){
                  // Adds up multiples of 5 which are not divisible by 3. 
			if(((5*i)%3) != 0) {
				sum+=(5*i);
			}

		}

		return sum;
	}
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.