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 IF statement problem 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 "IF statement problem" Watch "IF statement problem" New topic

IF statement problem

zoster gibrilian

Joined: Sep 17, 2003
Posts: 7
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

Joined: Sep 03, 2003
Posts: 399
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 ...
It is sorta covered in the JavaRanch Style Guide.
subject: IF statement problem
Similar Threads
Instance Pooling in Servlets
Confirmation required
SecurityException: Prohibited package name
What is the Advantage Of Prepared Statement Over Statement
How to submit a null in radio button