lundi 30 novembre 2015

Better alternative to long list of if statements

I have an int called dayCounter that runs 1 to 7. And i have a String called day. dayCounter increments every 10 seconds using TimerTask.

I use the following if statement inside the private void run() method used for TimerTask:

if (dayCounter == 1){
day = "Monday";}

I have an if statement like this for every day of the week. Is there a more efficient way which gets the same result. I was thinking maybe creating an array with holds String month and then increment it some way. But i wouldn't know how to go about it. Any ideas?

Aucun commentaire:

Enregistrer un commentaire