This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes image rotation based on a counter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "image rotation based on a counter" Watch "image rotation based on a counter" New topic
Author

image rotation based on a counter

Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
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

Joined: Oct 02, 2003
Posts: 11153
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
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

Joined: Oct 02, 2003
Posts: 11153
    
  16

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

Joined: May 31, 2007
Posts: 42
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image rotation based on a counter
 
Similar Threads
maintining two sessions in same browser window
How to maintain user name in all the Jsp pages
Location Finder(Urgent)!!!
x = b ? y : z ;
Background image in jscrollpane