Does anyone know of any sites where I might find some practical exercises where I could practice what I have learned so far. What I'm looking for is exercises that provide a scenario and then I have to work out how to program it.

Printable View

- 05-11-2011, 05:33 PMJohnPringle83need some exercises
Does anyone know of any sites where I might find some practical exercises where I could practice what I have learned so far. What I'm looking for is exercises that provide a scenario and then I have to work out how to program it.

- 05-11-2011, 06:26 PMDarrylBurke
Try Project Euler

db - 05-11-2011, 06:44 PMJohnPringle83
Thanks for that, that's just what I've been looking for and I already solved 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.

Code:`public class Problem1 {`

public static void main(String[] args){

int multiple1 = 3;

int multiple2 = 5;

int max = 1000;

int sum = 0;

int current = multiple1;

do{

if (current%multiple1==0||current%multiple2==0){

sum+=current;

}

current++;

}while(current<max);

System.out.println("The sum of all the multiples of "

+multiple1+" or "

+multiple2+" below "+max+" is "+sum);

}

}

- 05-11-2011, 06:53 PMKevinWorkman
- 05-11-2011, 06:57 PMJohnPringle83
I guess so, but it's the only one that I'm going to post. It was an easy one and I'm sure loads of people will be able to solve it without cheating. If they do cheat by looking at my source then they wont achieve anything.

I only have 336 problems left to solve, I think I'll just do one a day though. - 05-11-2011, 07:26 PMToll
I actually made a nice little GUI to combine all my solutions when I started poking around Project Euler. It looks about as ugly as all my programs do, but you (or someone else) might be able to prettify it. Basically, you name your classes Euler<number> (so Euler001 for problem 1, Euler002 for project 2, etc) and have it extend EulerSolution. For instance, my class for the first Euler project is:

Code:`class Euler001 extends EulerSolution`

{

long solve()

{

int solution=0;

// Solution goes here!

return solution;

}

}

- 05-11-2011, 07:26 PMToll
Oh, and make sure to run it from a console, because that's where the solution is printed.

- 05-11-2011, 07:28 PMsunde887
Codingbat is a good website for logic, recursion, string manipulation, and other types of challenge. Most are fairly simple but it definitely gets you used to a lot of the classes/primitives and how they work.

- 05-11-2011, 07:35 PMJohnPringle83
Thanks Toll,

I'm just figuring out how I can put this to use. If I make any improvements to it in the future, I will let you know and see.

Thanks Sunde887,

I was just going to ask if anyone knew of any sites like this that wasn't entirely dedicated to mathematical programming. - 05-11-2011, 07:46 PMJohnPringle83
I just tried that codingbat website and when I clicked go after writing the code, nothing happened. I was expecting it to tell me if I was right or wrong, and also I thought I would click the show solution button and still nothing happened.:(

- 05-11-2011, 07:48 PMJohnPringle83
Actually forget that, I just noticed that the result appears to the right of the page :)