# Thread: Want some material for practicing loop

1. Member
Join Date
Jul 2011
Posts
39
Rep Power
0

## 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. 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. 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. 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. Member
Join Date
Jul 2011
Posts
39
Rep Power
0
Thanks, will try it.

6. Member
Join Date
Jun 2011
Posts
23
Rep Power
0
try the basic things before you go to array...

7. Member
Join Date
Jul 2011
Posts
39
Rep Power
0
You are absolutely right, but from where I can get basic things with the solutions.

8. 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. Senior Member
Join Date
Nov 2010
Posts
164
Rep Power
4
OH yes...This isn't good!

10. Senior Member
Join Date
Nov 2010
Posts
164
Rep Power
4
...and by that I mean, this is good...but distracting for curious newcomers...:)

11. Member
Join Date
Jul 2011
Posts
39
Rep Power
0
ok, i will try to make it and let you know if I am facing some problems. Thanks

12. Senior Member
Join Date
Nov 2010
Posts
164
Rep Power
4
...Darn you java-forums...now I'm sucked in...

#### Posting Permissions

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