Month Name

Write a function. It will return the name of a month of the year, given the month number, according to the table below. Make sure you do not put any input or output statements in the function; the month number will be passed in and the string containing the name will be returned.

NumberMonth
1January
2February
3March
4April
5May
6June
7July
8August
9September
10October
11November
12December
anything elseerror

The function must be called month_name(), and must have one parameter (an integer), and return a String.

And finally, here's some starter code.

public static void main( String[] args )

    System.out.println( "Month 1: " + month_name(1) );
    System.out.println( "Month 2: " + month_name(2) );
    System.out.println( "Month 3: " + month_name(3) );
    System.out.println( "Month 4: " + month_name(4) );
    System.out.println( "Month 5: " + month_name(5) );
    System.out.println( "Month 6: " + month_name(6) );
    System.out.println( "Month 7: " + month_name(7) );
    System.out.println( "Month 8: " + month_name(8) );
    System.out.println( "Month 9: " + month_name(9) );
    System.out.println( "Month 10: " + month_name(10) );
    System.out.println( "Month 11: " + month_name(11) );
    System.out.println( "Month 12: " + month_name(12) );
    System.out.println( "Month 43: " + month_name(43) );
}

Month 1: January
Month 2: February
Month 3: March
Month 4: April
Month 5: May
Month 6: June
Month 7: July
Month 8: August
Month 9: September
Month 10: October
Month 11: November
Month 12: December
Month 43: error


©2013 Graham Mitchell

This assignment is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
Creative Commons License