Reputation: 23
Here is my code:
public class CalendarDisplay {
public static boolean isLeapYear(int year)
{
return (year %400 == 0) ||
(year %4 == 0 && year %100 != 0);
}
public static void main(String[] args) {
int year = Integer.parseInt(args[0]);
int month = Integer.parseInt(args [1]);
boolean leapYear = isLeapYear(year);
System.out.println("The Year " + year + ((leapYear == true)?
" is": " is not") + " a leap year");
int days = 0;
switch(month)
{
case 4: case 6: case 9: case 11:
days=30;
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
days = 31;
case 2:
days = (leapYear == true)? 29:28;
break;
default:
System.out.println ("error!");
break;
}
System.out.println("The Month " + month + " has " + days);
}
public static String getMonthName (int month) {
String monthName = "";
switch(month)
{
case 1:
monthName = "January";
break;
case 2:
monthName = "Feburary";
break;
case 3:
monthName = "March";
break;
case 4:
monthName = "April";
break;
case 5:
monthName = "May";
break;
case 6:
monthName = "June";
break;
case 7:
monthName = "July";
break;
case 8:
monthName = "August";
break;
case 9:
monthName = "September";
break;
case 10:
monthName = "October";
break;
case 11:
monthName = "November";
break;
case 12:
monthName = "December";
break;
}
return monthName;
}
}
at the command line I input: 2014 02
The output is this:
"The Year 2014 is not a leap year The Month 2 has 28"
I need "Month 2" to say "Month February"
Thank you
Upvotes: 2
Views: 91
Reputation: 49714
Since your getMonthName
function returns a String value, your System.out.println
can call the getMonthName
method and use the result as part of the output.
System.out.println("The Month " + getMonthName(month) + " has " + days + " days");
Upvotes: 1