Java language Programming (Basic) 10th edition 13.4

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.