Display Current Month Name using Array and Select Case
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class Month_Name
{
public static void main(String[] args)
{
Date dt=new Date();
System.out.println(dt.getMonth());
String Month_Name[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
switch (dt.getMonth())//(c.MONTH+1)
{
case 0:
System.out.println(Month_Name[0]);
break;
case 1:
System.out.println(Month_Name[1]);
break;
case 2:
System.out.println(Month_Name[2]);
break;
case 3:
System.out.println(Month_Name[3]);
break;
case 4:
System.out.println(Month_Name[4]);
break;
case 5:
System.out.println(Month_Name[5]);
break;
case 6:
System.out.println(Month_Name[6]);
break;
case 7:
System.out.println(Month_Name[7]);
break;
case 8:
System.out.println(Month_Name[8]);
break;
case 9:
System.out.println(Month_Name[9]);
break;
case 10:
System.out.println(Month_Name[10]);
break;
case 11:
System.out.println(Month_Name[11]);
break;
}
}
}
No comments:
Post a Comment