Forums Register Login

Just wrote a method which makes my computer's processor go MENTAL. Can anyone tell me why?

+Pie Number of slices to send: Send
Ok then i had an idea today that i would try and make a card game. Before I start programing the game properly i started experimenting with things. First i got it into my head that i would represent each card in the deck by using two arrays - one for suit and one for the card number.

Then i kind of just started jamming and learning. Here i was trying to make a way so that once the card had been dealt it wouldn't be dealt again. Anyway i'll post the code first before i continue.





There is one other class that has the main method, that starts another method that invokes the dealRandomCard method.

Please just think of this as a rough draft, more like a doodle. Or an experiment to see what is possible using array lists and arrays.

The problem is that when i compile and run the program (either in eclispe or using command promt, the program runs fine, but then one of my processors (i have a quadcore) maxes out to 100%, and then it stays there until i either close eclispse or exit the command prompt.

What an earth is going on? Why is it doing this?

Sorry if the code seems a bit random. Maybe i should add some comments to say what is doing what. Or maybe it will be obvious to a none beginner i don't know.

+Pie Number of slices to send: Send
I think i've just worked it out.

it's cause the for loop NEVER ends!


hope someone hasn't gone to the trouble of writing a big long reply!
+Pie Number of slices to send: Send
Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!
+Pie Number of slices to send: Send
 

Greg Charles wrote:Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!



haha i can't believe i did that!

If anyone is wondering what the heck i was thinking of. I was thinking that i wanted the for loop to go until i had printed out 52 cards, and if a certain card generated by a random number had already been generated i wanted the for loop to go again like nothing had happend. Oh well i think i would be better off using a while loop and just incrementing a variable everytime a card is printed out.

When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 941 times.
Similar Threads
can't split card shuffle method into a separate class
blackjack java
Problems overwriting toString() method.
Help With 5 card stud program
class question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:01:09.