Results 1 to 12 of 12
  1. #1
    gozuhair is offline Member
    Join Date
    Jul 2011
    Posts
    39
    Rep Power
    0

    Default Want some material for practicing loop

    Hi All
    I am beginner in Java and wanna do some beginners and intermedite level practice on loop,can someone refer me or send me some beginner and intermediate practice exercise for loop.

    Regards

    Khan

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

    Default

    Some quick ones off the top of my head:
    calculate the nth Fibonacci number with 0 as 0, and 1 as 1.
    Calculate the nth prime
    Euclids algorithm for GCD: if m%n==0, gcd is n, m<-n, n<-m%n
    Sorting algorithms generally use loops as well, look up the ideas behind a few and try implementing them

    Check out projecteuler.com and codingbat.com

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,792
    Rep Power
    25

    Default

    Create an int array with some numbers in it. For example: {3, 5, 7, 2, 1,11,0,33}
    and write a loop to find the largest and smallest values in the array.
    Create another array to hold indexes to the first array. Fill that array with the indexes to the first array in sorted order.
    The first element has the index to the lowest value in the first arrray, the next element the index to the next higher value.

  4. #4
    Joel's Avatar
    Joel is offline Member
    Join Date
    May 2011
    Location
    Placerville, CA
    Posts
    86
    Rep Power
    0

    Default

    Make a Lottery program. Set an int[] array to 7 digits (use Math.Random() to generate list), which will be the winning ticket. Then load another array (user array) and sort through both arrays using for loop to test if there are any matches. If you get all seven numbers then you win the jackpot, 6 out of 7 some other prize, and so on. Be sure to test data for all different tickets.

  5. #5
    gozuhair is offline Member
    Join Date
    Jul 2011
    Posts
    39
    Rep Power
    0

    Default

    Thanks, will try it.

  6. #6
    aviolently is offline Member
    Join Date
    Jun 2011
    Posts
    23
    Rep Power
    0

    Default

    try the basic things before you go to array...

  7. #7
    gozuhair is offline Member
    Join Date
    Jul 2011
    Posts
    39
    Rep Power
    0

    Default

    You are absolutely right, but from where I can get basic things with the solutions.

  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

    Why not choose something people here have suggested and give it your best attempt, if you get stuck, we will gladly help you along. The Fibonacci one is a favorite of mine for beginners since it takes a bit of thinking

  9. #9
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    5

    Default

    OH yes...This isn't good!

  10. #10
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    5

    Default

    ...and by that I mean, this is good...but distracting for curious newcomers...:)

  11. #11
    gozuhair is offline Member
    Join Date
    Jul 2011
    Posts
    39
    Rep Power
    0

    Default

    ok, i will try to make it and let you know if I am facing some problems. Thanks

  12. #12
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    167
    Rep Power
    5

Similar Threads

  1. New to Web Services looking for good reading material
    By DuceDuceExplorer in forum Web Frameworks
    Replies: 0
    Last Post: 06-29-2011, 04:53 PM
  2. Practicing Concurrency
    By sunde887 in forum New To Java
    Replies: 1
    Last Post: 06-21-2011, 04:27 AM
  3. Practicing Java
    By sumithra in forum New To Java
    Replies: 4
    Last Post: 07-11-2010, 03:09 PM
  4. A problem in practicing the array
    By dl21 in forum New To Java
    Replies: 2
    Last Post: 04-25-2008, 12:32 AM

Posting Permissions

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