# Finding number of days in a month confusion

Mezan Shareef
Ranch Hand
Posts: 40
To write a program to prompt the user to enter month and year, and display number of days in a month. for example if user entered month 2 and year 2000 the program should display that Feb 2000 has 29 days. if user enters month 3 year 2005, program should display Mar 2005 has 31 days.

I am unable to strategize my mind, i am stuck i did little bit, how can i do the rest part. please help.

Jean Fontaine
Greenhorn
Posts: 12
Hi.
Well, at first you should make a switch to say : case 1 : month = "JAN"
case 2 : month = "FEB" ...
Then say if (month.equals("JAN") || month.equals("MAR") ...)
{ days = 31; }
else if (month.equals("APR") || month.equals("JUN")...
{days = 30 }

gotcha ?

Mezan Shareef
Ranch Hand
Posts: 40
I did what you said jean it throws 2 errors for the changes you said.

Type incompatible for case change you said.

int can not be dereferenced for the if statement change.

can you please again think. I am shut off. This is why it becomes tough for me to learn java. i always get stuck so that, i can not recover from errors... please help me guys, this time i do not want to quit while learning this dirty java.

Wouter Oet
Saloon Keeper
Posts: 2700
Do you keep leap years in mind? Cause your solution now doesn't. I'll give you a hint: Calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
And DateFormat can provide the month names.

Jean Fontaine
Greenhorn
Posts: 12
Hmmm...
It's because month is an int.
You have t make a Stirng named monthName, then say :

case 1 : monthName = "JAN" etc..
Then it should do.

edit : oh and replace if month.equals() by if monthName.equals().
another edit : also, instead of
if { }
if {}
if { },
say
if { }
else if { }
else if { }

You also have to initialize your String by saying String monthName = ""

LAST EDIT : WORKS FOR ME !

Campbell Ritchie
Sheriff
Posts: 51344
86
Another possibility:This is a very basic and rudimentary block, which will require a lot of refinement. And remember that inJavaâ„¢ January = 0 and December = 11.

Mezan Shareef
Ranch Hand
Posts: 40
THank you Guys, !! Your sugestions helped. IT also worked for me.

Wouter Oet
Saloon Keeper
Posts: 2700
What did you end up using?

Campbell Ritchie
Sheriff
Posts: 51344
86
Wouter Oet wrote:What did you end up using?
Whichever you used: "You're welcome"

Jean Fontaine
Greenhorn
Posts: 12
No problem !