# Want some material for practicing loop

• 07-29-2011, 09:24 AM
gozuhair
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
• 07-29-2011, 10:06 AM
sunde887
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
• 07-29-2011, 02:00 PM
Norm
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.
• 07-29-2011, 06:13 PM
Joel
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.
• 07-29-2011, 10:07 PM
gozuhair
Thanks, will try it.
• 07-30-2011, 12:15 PM
aviolently
try the basic things before you go to array...:frusty::frusty::frusty::frusty:
• 07-30-2011, 01:05 PM
gozuhair
You are absolutely right, but from where I can get basic things with the solutions.
• 07-30-2011, 02:01 PM
sunde887
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
• 07-30-2011, 07:16 PM
bigsonny
OH yes...This isn't good!
• 07-30-2011, 07:17 PM
bigsonny
...and by that I mean, this is good...but distracting for curious newcomers...:)
• 07-30-2011, 10:01 PM
gozuhair
ok, i will try to make it and let you know if I am facing some problems. Thanks
• 07-30-2011, 10:23 PM
bigsonny
...Darn you java-forums...now I'm sucked in...