Here is the full question: (Finding the number of days in a month) Write a progr
ID: 3629407 • Letter: H
Question
Here is the full question:
(Finding the number of days in a month) Write a program that prompts the user to enter the month and year and displays the number of days in the month. For example, if the user entered month 2 and year 2000, the program should display that February 2000 has 29 days. If the user entered month 3 and year 2005, the program should display that March 2005 has 31 days.
Where I'm stuck:
I'm including a print screen of my code from Netbeans. It seems that my boolean statement for February leap years is not correct. I've looked a it several times. Can someone tell me where I'm going wrong?
Here is the screen shot of Netbeans:
Explanation / Answer
please rate - thanks
your screen shot is impossible to read
try this, it should help
import java.util.*;
public class daysinmonth
{
public static void main(String[] args)
{Scanner in = new Scanner(System.in);
int month,year,days=0;
String m="";
System.out.print("Enter month(1-12): ");
month=in.nextInt();
System.out.print("Enter year: ");
year=in.nextInt();
if(month<1||month>12)
System.out.println("InValid date");
else
{if(month==1)
{days=31;
m="January";
}
else if(month==2)
{days=28;
m="Febuary";
if(year%4==0)
if(year%100==0)
{if(year%400==0)
days++;
}
else
days++;
}
else if(month==3)
{days=31;
m="March";
}
else if(month==4)
{days=30;
m="April";
}
else if(month==5)
{days=31;
m="May";
}
else if(month==6)
{days=30;
m="June";
}
else if(month==7)
{days=31;
m="July";
}
else if(month==8)
{days=31;
m="August";
}
else if(month==9)
{days=30;
m="Septemper";
}
else if(month==10)
{days=31;
m="October";
}
else if(month==11)
{days=30;
m="November";
}
else if(month==12)
{days=31;
m="December";
}
}
System.out.println(m +" "+year+" has "+days+" days");
}
}