java练习2

复制代码
package a01_第一次练习.a02_计算输入天数;

import java.text.ParseException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) throws ParseException {
        //当前时间
        LocalDateTime Today = LocalDateTime.now();

        //输入时间
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份");
        int year = sc.nextInt();
        System.out.println("请输入月份");
        int month = sc.nextInt();
        System.out.println("请输入日期");
        int day = sc.nextInt();
        LocalDateTime scDate = LocalDateTime.of(year, month, day,0,0);

        //相差天数
        System.out.println("相差的天数:" + Duration.between(scDate, Today).toDays());
    }
}

sc.nextInt()获取年月日

相关推荐
马优晨6 分钟前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯1 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_446260851 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao2 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest
人邮异步社区2 小时前
怎么把C语言学到精通?
c语言·开发语言
qetfw2 小时前
MXU:Tauri 2 + React 的 MaaFramework 跨平台 GUI 源码
前端·python·react.js·前端框架·开源项目·效率工具
心平气和量大福大2 小时前
C#-WPF-控件-TextBox 数据绑定
开发语言·c#·wpf
ttwuai3 小时前
Cursor 生成 CRUD 后,Go 后台接口别只测 200:JWT、RBAC 和 tenant_id 怎么验
开发语言·后端·golang
用户8356290780513 小时前
Python 实现 Excel 页面布局与打印设置自动化
后端·python