当前位置:网站首页>二月天
二月天
2022-07-21 11:09:00 【编程奥特曼.】
package itheima_03;
import java.util.Calendar;
import java.util.Scanner;
/*
需求:
获取任意一年的二月有多少天
思路:
1: 键盘录入任意的年份
2: 设置日历对象的年、月、日
年: 来自于键盘录入
月:设置为3月,月份是从0开始的,所以设置的值是2
日: 设置为1日
3: 3月1日往前推一天,就是2月的最后一天
4: 获取这一天输出即可*/
public class CalendarTest {
public static void main(String[] args) {
//键盘录入任意年份
Scanner sc = new Scanner(System.in);
System.out.println(“请输入年份:”);
int year = sc.nextInt();
//设置日历对象的年、 月、日
Calendar c = Calendar.getInstance();
c.set(year,2,1);
//3月1日往前推一天,就是2月的最后一天
c.add(Calendar.DATE,-1);
//获取这一天输出即可
int date = c.get(Calendar.DATE);
System.out.println(year+ "年的2月份有" + date + "天");
}
}
边栏推荐
- Idea 2020.1 cancel parameter name display
- 多模态模型 CLIP4Clip 带你实现文本与视频互搜
- Part 93 inter contract transfer (II)
- SAP ABAP parsing function text of Excel file_ CONVERT_ XLS_ TO_ SAP single step analysis
- 定时任务框架
- NPM and the development history of yarn
- Techempower web框架性能测试第21轮结果发布--asp.net core继续前进
- Part 98 Truffle
- Unity的相机的世界坐标Postion、Rotation、Scale怎样转换成View矩阵
- ModelArts、盘古大模型、ModelBox…详解华为云AI开发生产线
猜你喜欢
Run busybox, buildroot, loognix, qt5.12 system for Godson development board process
A trick to teach you how to master online videos
The training accuracy is comparable to alphafold2, and the speed is doubled. The helixfold training and reasoning code of the propeller is fully open source
浏览器缓存机制解析
Browser cache mechanism resolution
Code management (novice)
ANSVC无功补偿装置助力江苏某环保能源项目
SAP ABAP parsing function text of Excel file_ CONVERT_ XLS_ TO_ SAP single step analysis
【全网首发】Redis系列4:高可用之Sentinel(哨兵模式)
訓練精度媲美 AlphaFold2、速度翻倍,飛槳螺旋槳HelixFold訓練和推理代碼全面開源...
随机推荐
Fiddler oS. Invalid problem of utilsetresponsebody
Intel汇编程序设计-整数算术指令(上)
Part 94 inter contract transfer (III)
Gsyvideoplayer slide refresh video
zooInspector 下载
“F5G+EIoT“构建能源物联网,助力电力物联网数据服务
Intel assembler programming - integer arithmetic instructions (Part 1)
生物制药安全供电保生产
(板子)筛素数--线性筛和埃氏筛
编译原理实验1——词法分析程序设计原理与实现
【全网首发】Redis系列4:高可用之Sentinel(哨兵模式)
(plate) sieve prime number -- linear sieve and Ehrlich sieve
Learning notes of Stanford CV course (I)
Chapter 106 governance in compound
浏览器缓存机制解析
【2022年中总结】我走得很慢,但我从不后退
第100篇 兼容 ETH 与 ERC20 的库合约
SystemVerilog:如何指定仿真源文件?
A trick to teach you how to master online videos
Yarn 的 Plug‘n‘Play 特性