Tuesday, 22 December 2015

Program to accept a number and display corresponding Month from an array

Java Program to print the Month Name


Demonstrate array operation using Month Name display program in Java


Program

public class MonthNameDisplay
{
    static String months[] =
    {
        null , "January" , "February" , "March" , "April", "May",
        "June", "July", "August", "September", "October",
        "November", "December"
    };
    public static void main( String[] args )
    {
        int m = Integer.parseInt( args[0] );
        System.out.println( months[ m ] );
    }
}

Output


java MonthNameDisplay 2
February

No comments :

Post a Comment