1. Member
Join Date
May 2011
Posts
64
Rep Power
0

## need 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.

2. Try Project Euler

db

3. Member
Join Date
May 2011
Posts
64
Rep Power
0
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.

Java 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);

}
}```

4. Originally Posted by JohnPringle83
Thanks for that, that's just what I've been looking for and I already solved problem 1:
Just out of curiosity, why are you posting it here? Aren't you supposed to keep the answers to those questions a bit "under your hat" as it were?

5. Member
Join Date
May 2011
Posts
64
Rep Power
0
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.

6. 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:
Java Code:
```class Euler001 extends EulerSolution
{
long solve()
{
int solution=0;
// Solution goes here!
return solution;
}
}```
Feel free to use and/or expand it!

7. Oh, and make sure to run it from a console, because that's where the solution is printed.

8. 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.

9. Member
Join Date
May 2011
Posts
64
Rep Power
0
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.

10. Member
Join Date
May 2011
Posts
64
Rep Power
0
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.:(

11. Member
Join Date
May 2011
Posts
64
Rep Power
0
Actually forget that, I just noticed that the result appears to the right of the page :)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•