Java - how to count loops

  • Java
  • Thread starter schapman22
  • Start date
  • #1
74
0
For my class I need to make a "Guessing Game" Program. Basically you just pick a number between 1-1000. It tells you if you are too high, too low, or correct. If your too high or low you guess again until you get it right. When you get it right it is supposed to tell you how many tries it took you. I have it running properly but I don't know how to count how many times the loop ran, which is the number I would need for the response when you guess the correct number. Can anyone tell me how to count the number of times a loop runs?
 

Answers and Replies

  • #2
diazona
Homework Helper
2,175
6
Use a counter variable. You just add 1 each time the thing you want to count happens (i.e. add 1 each time through the loop) and check its value at the end.
 
  • #3
74
0
Thank you.
 

Related Threads on Java - how to count loops

  • Last Post
Replies
2
Views
2K
Replies
2
Views
862
Replies
9
Views
11K
  • Last Post
Replies
4
Views
2K
Replies
8
Views
2K
Replies
4
Views
2K
Replies
6
Views
33K
Replies
2
Views
2K
Replies
3
Views
11K
Top