This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IF statement problem

 
zoster gibrilian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need an if statement that determines the number of days in the month entered by the user.
Also a switch statement would be fine...right?
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either an IF or a SWITCH would work, but you'd have to check for whether it is a leap year when doing February. Alternately you can use the "java.util.Calendar" class, calling the "getActualMaximum(...)" method with the correct field. You'd create the calendar, set the year and the month, and then call the "getActualMaximum(...)" method.
An IF would look something like (assuming the month is an integer where January==1; if not, adjust code accordingly):

You could also set up a static int array that contains the days in each month, and then use the month number as the array index. Again, you'll have to adjust for leap year.
So you have lots of choices ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic