• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counter to count Random occurence  RSS feed

 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new at Java and not very experienced with it and I have 2 classes a main one and another class. In the other class I have a method that has:



I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and for the love of god I cannot figure out how to get it to work correctly.

Any help would be greatly appreciated.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are using to store the occurrences of the behaviors? Where did you get stuck with your looping code?
 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the thing I really don't know how to go about doing it... I thought about doing an if statement for each array value such as Behavior[0] to rNum, but I don't really know how to go about setting the loop up... Mostly what I'm asking for is an example or tips on how to go about doing it.
 
Carey Brown
Saloon Keeper
Posts: 3315
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ricky Peddicord
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to know how to do it with a loop for each result.

in the main class I loop it 20 times and results in a random assortment of the Behavior values, but I don't know how to go about updating a counter for each one. I know you store each in and integer variable, but I'm not sure on how to loop to update the counter.

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a counting example in the Java® Tutorials, it is in the bit about Maps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!