Results 1 to 11 of 11
  1. #1
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default 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. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Try Project Euler

    db

  3. #3
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    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. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Quote Originally Posted by JohnPringle83 View Post
    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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    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. #6
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default

    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!
    Attached Files Attached Files

  7. #7
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    393
    Rep Power
    4

    Default

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

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

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

    Default

    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. #10
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    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. #11
    JohnPringle83 is offline Member
    Join Date
    May 2011
    Posts
    64
    Rep Power
    0

    Default

    Actually forget that, I just noticed that the result appears to the right of the page :)

Similar Threads

  1. OOP exercises
    By sunde887 in forum New To Java
    Replies: 6
    Last Post: 01-09-2011, 09:05 PM
  2. Exercises
    By amzers in forum New To Java
    Replies: 6
    Last Post: 12-12-2010, 10:58 AM
  3. A place to post beginner/inter exercises/scenarios
    By helpisontheway in forum New To Java
    Replies: 0
    Last Post: 01-27-2010, 10:03 AM
  4. Some exercises
    By javaamateur in forum New To Java
    Replies: 7
    Last Post: 12-02-2009, 01:00 AM
  5. Exercises
    By lclclc in forum New To Java
    Replies: 3
    Last Post: 09-14-2009, 11:20 PM

Posting Permissions

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