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

Printable View

- 07-29-2011, 10:24 AMgozuhairWant 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, 11:06 AMsunde887
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, 03:00 PMNorm
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, 07:13 PMJoel
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, 11:07 PMgozuhair
Thanks, will try it.

- 07-30-2011, 01:15 PMaviolently
try the basic things before you go to array...:frusty::frusty::frusty::frusty:

- 07-30-2011, 02:05 PMgozuhair
You are absolutely right, but from where I can get basic things with the solutions.

- 07-30-2011, 03:01 PMsunde887
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, 08:16 PMbigsonny
OH yes...This isn't good!

- 07-30-2011, 08:17 PMbigsonny
...and by that I mean, this is good...but distracting for curious newcomers...:)

- 07-30-2011, 11:01 PMgozuhair
ok, i will try to make it and let you know if I am facing some problems. Thanks

- 07-30-2011, 11:23 PMbigsonny
...Darn you java-forums...now I'm sucked in...