Results 1 to 11 of 11
Thread: need some exercises
- 05-11-2011, 05:33 PM #1
Member
- Join Date
- May 2011
- Posts
- 64
- Rep Power
- 0
- 05-11-2011, 06:26 PM #2
Try Project Euler
db
- 05-11-2011, 06:44 PM #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); } }
- 05-11-2011, 06:53 PM #4
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-11-2011, 06:57 PM #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.
- 05-11-2011, 07:26 PM #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:
Feel free to use and/or expand it!Java Code:class Euler001 extends EulerSolution { long solve() { int solution=0; // Solution goes here! return solution; } }
- 05-11-2011, 07:26 PM #7
Oh, and make sure to run it from a console, because that's where the solution is printed.
- 05-11-2011, 07:28 PM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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 PM #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.
- 05-11-2011, 07:46 PM #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.:(
- 05-11-2011, 07:48 PM #11
Member
- Join Date
- May 2011
- Posts
- 64
- Rep Power
- 0
Similar Threads
-
OOP exercises
By sunde887 in forum New To JavaReplies: 6Last Post: 01-09-2011, 08:05 PM -
Exercises
By amzers in forum New To JavaReplies: 6Last Post: 12-12-2010, 09:58 AM -
A place to post beginner/inter exercises/scenarios
By helpisontheway in forum New To JavaReplies: 0Last Post: 01-27-2010, 09:03 AM -
Some exercises
By javaamateur in forum New To JavaReplies: 7Last Post: 12-02-2009, 12:00 AM -
Exercises
By lclclc in forum New To JavaReplies: 3Last Post: 09-14-2009, 10:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks