Import java.util.*;
public class Exercise13_04 {
public static void Main (string[] args) {
Scanner input = new Scanner (system.in);
System.out.println ("Enter month and Year:");
Printcalendar Y = new Printcalendar (Input.nextint (), Input.nextint ());
Y.printmonthtitle (); Y.printmonthbody ();
}
}
Class Printcalendar {
Calendar value;
Public Printcalendar (int Month, int.) {value = new GregorianCalendar (year, Month, 1); }
public void Printmonthtitle () {
System.out.println ("" + Getmonthname (Value.get (calendar.month) + "" + value.get (calendar.year));
System.out.println ("----------------------------------");
System.out.println ("Sun Mon Tue Wed Thu Fri Sat"); }
Public String getmonthname (int month)
{String monthName = "";
Switch (month)
{
Case 1:monthname = "January"; Break
Case 2:monthname = "February"; 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";
}
return monthName;
}
public void Printmonthbody ()
{
int startday = Value.get (Calendar.day_of_week)-1;
int numberofdaysinmonth = Value.getactualmaximum (calendar.day_of_month);
int i = 0; for (i = 0; i < startday; i++) System.out.print ("");
for (i = 1; I <= numberofdaysinmonth; i++)
{
System.out.printf ("%4d", I);
if ((i + startday)% 7 = = 0)
System.out.println ();
}
System.out.println ();
}
}
Java language Programming (Basic) 10th edition 13.4