File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image rotation based on a counter

 
Avi Sridhar
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,I have a requirement that is to have image x, shown when the user has first logged in, image y the second time logged in, then from the 3rd login the image should be image x 4th login image y 5th login should be x again 6th login should be y, you see a pattern here.

Please let me know how I can put this in logic.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to store somewhere how many times the user has logged in. then simply take it mod 2 to determine which image to display.
 
Avi Sridhar
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
you need to store somewhere how many times the user has logged in. then simply take it mod 2 to determine which image to display.


Thanks for your help. Can you please provide an example. I have the number of times the user has logged in, but ... you mean we must know how many images to display, her for example there are 2 images to display, thats the reason you are using mod 2, if there are n images then it will be mod n is it.

Can you please give an example.

Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12015
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of an example do you want? you seem to have the concept.

k % n will return an integer from 0 to (n-1). you simply use that as the index into whichever image you want to display.
 
Avi Sridhar
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
What kind of an example do you want? you seem to have the concept.

k % n will return an integer from 0 to (n-1). you simply use that as the index into whichever image you want to display.


Thanks , I got it
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic