JAVA语言程序设计(基础篇)第10版 13.4
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA语言程序设计(基础篇)第10版 13.4相关的知识,希望对你有一定的参考价值。
import java.util.*;
public class Exercise13_04 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("输入月份和年份:");
PrintCalendar Y = new PrintCalendar(input.nextInt() , input.nextInt());
Y.printMonthTitle(); Y.printMonthBody();
}
}
class PrintCalendar {
Calendar value;
public PrintCalendar(int Month , int Year) { 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语言程序设计(基础篇)第10版 13.4的主要内容,如果未能解决你的问题,请参考以下文章
开发版iOS 13.4macOS 10.15.4 Beta 4 已发布