public class Demo01 {
/**
* 输出指定年份每月最大的天数
* author:wangpeng
* time:2018年8月9日下午4:04:33
*/
@Test
public void test1() {
Scanner in = new Scanner(System.in);
System.out.println("输入年份:");
String str = in.next();
int year = 0;
if (str.matches("\\d+")) {
year = Integer.parseInt(str);
} else {
System.out.println("输入有误");
return;
}
// 创建日历类
Calendar c = Calendar.getInstance();
// Calendar c=new GregorianCalendar();
if (year > 0)
c.set(Calendar.YEAR, year);
System.out.println("用户输入的年份:" + year);
for (int i = 0; i < 12; i++) {
c.set(Calendar.MONTH, i);
// 得到当前月份的最大天数
int actualMaximum = c.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(i + 1 + "月最大天数:" + actualMaximum);
}
}
}
Java之日历类 输出指定年份每月最大的天数
猜你喜欢
转载自blog.csdn.net/qq_34361514/article/details/81607584
今日推荐
周排行