需求: 获取任意一年的二月有多少天
思路:
package second_month;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class Second_Month {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入年份:");
int year = sc.nextInt();
//.getInstance()是一种设计方法,并非具体方法,作用和new类似
Calendar c = Calendar.getInstance();
//设置年月日 输入的年, 3月由于是0开始计算月所以是2,日期为1日
c.set(year, 2, 1);
// 把日期设置为3月1日的前一天
c.add(Calendar.DATE, -1);
// 取得3月一日的前一天日期
int date = c.get(Calendar.DATE);
System.out.println("在" + year + "年的二月有" + date + "天");
}
}
推荐阅读:
vue.js:634 [Vue warn]: Property or method "userName" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:
状态码:415,发送HTTP请求返回415状态码的解决办法
SpringBoot 整合 webapp时 访问404的解决办法
Vue 打开页面时就加载方法,例如查询
SpringCloud怎么调用多个服务的信息
Spring整合Mybatis
SpringCloud 加入 thymleaf前端页面的方法
Controller之间的跳转
Spring AOP的实现原理
This may be the result of an unspecified view, due to default view name generation
行动消除疑虑