• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calculating the number of user inputs?  RSS feed

 
Linda Selfridge
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone tell me the easiest way to calculate the number of user inputs?

Thanks

 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would just count them, rather than trying to "calculate" the number. Of course it all depends on what you mean by a "user input", so a lot more information would be required if you wanted a more useful answer than that.
 
Linda Selfridge
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about that...

I am putting together a program that uses user input the update the position of a point within a square. The user is prompted on a loop to input a direction using letters such as up, down, left or right (not using arrows) until such time as the point reaches the boundary of the square.

Upon reaching the boundary the program needs to terminate and calculate the number of moves it has taken to reach the boundary. It really depends on the user it could take 4 moves or it could take anywhere up to 8 moves etc.

I can't put my code in yet because I am working on the OCD at the moment and working out calculations etc.

any help would be appreciated.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're just counting moves, you could use a simple int counter and increment it (counter++) with every move. If you have to keep track of direction, you could do right, left, up, and down counters, but it didn't sound like you needed that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!