快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记娱乐AG手机版_机器人论坛



/**

* @author bzwm*

*/ import java.io.BufferedReader;

import java.io.IOException;import java.io.InputStreamReader;

import java.util.Calendar;import java.util.GregorianCalendar;

public class C和记娱乐AG手机版alendarTest {

public static void main(String[] args) throws IOException {BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

System.out.print("请输入一个年份:");String years = 和记娱乐AG手机版in.readLine();

CalendarPrinter cp = new CalendarPrinter(years);cp.printCal();

}}

class CalendarPrinter {

private int year;

private static final int monthCount = 12;

public CalendarPrinter(String years) {

if (!years.matches("\\d{4}")) {System.out.println("year that inputted is illagel.");

return;}

year = Integer.parseInt(ye和记娱乐AG手机版ars);}

public void printCal() {

// construct d as current dateGregorianCalendar gCal = new GregorianCalendar();

//set year

gCal.set(Calendar.YEAR, year);for (int month = 0; month

gCal.set(Calendar.MONTH, month);printOut(和记娱乐AG手机版gCal);

}}

private void printOut(Calendar cal) {

int month = cal.get(Calendar.MONTH);

// set cal to start date of the monthcal.set(Calendar.DAY_OF_MONTH, 1);

int weekday = cal.get(Calendar.DAY_OF_WEEK);

// print heading

System.out.println("Sun Mon Tue Wed Thu Fri Sat");

// indent first line of calendarfor (int i = Calendar.SUNDAY; i

System.out.print("");

do {// print day

int day = cal.get(Calendar.DAY_OF_MONTH);if (day > 0)

System.out.print(" " + day + " ");else

System.out.print("" + day + " ");

// s和记娱乐AG手机版tart a new line after every Saturdayif (weekday == Calendar.SATURDAY)

System.out.println();

// advance d to the next daycal.add(Calendar.DAY_OF_MONTH, 1);

weekday = cal.get(Calendar.DAY_OF_WEEK);} while (cal.get(Calendar.MONTH) == month);

// the loop exits when d is day 1 of the next month

// print final end of line if necessaryif (weekday != Calendar.SUNDAY)

System.out.println();}

}

您可能还会对下面的文章感兴趣: