V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  soulflysimple123  ›  全部回复第 4 页 / 共 6 页
回复总数  109
1  2  3  4  5  6  
javaboy 来了

private static void calculateTime(int second) {
Duration duration = Duration.ofSeconds(second);
StringBuilder builder = new StringBuilder();
if (duration.toDays()> 0) {
builder.append(duration.toDays()).append("天");
duration = duration.minus(Duration.ofDays(duration.toDays()));
}
if (duration.toHours() > 0) {
builder.append(duration.toHours()).append("小时");
duration = duration.minus(Duration.ofHours(duration.toHours()));
}
if (duration.toMinutes() > 0) {
builder.append(duration.toMinutes()).append("分");
duration = duration.minus(Duration.ofMinutes(duration.toMinutes()));
}
builder.append(duration.getSeconds()).append("秒");
System.out.println(builder.toString());
}
74 天前
回复了 nonames 创建的主题 职场话题 年后找工作有感
南京行情这么差了吗,前年几个外包还能给到 18k ,e 公司如果不加班不出差也还可以了,现在找工作别想着学技术了
74 天前
回复了 wuzhu 创建的主题 Java 请教等保测评和 jdk 版本的问题
升级 SpringBoot3 很多配置要改,还有 javaee,swagger 的注解也要改
75 天前
回复了 janpun 创建的主题 宽带症候群 江苏宽带有没有什么高性价比套餐啊
用移动芒果卡 300M 宽带,每月加 5 块升级到千兆
这个价格可以看国产那几个 2.0t 艾瑞泽 8 ,星瑞,影豹
从来不背,公司是台式机
默认的 dark modern
78 天前
回复了 momowei 创建的主题 Apple 苹果的软件能力是不是没有想的那么厉害
这么多年了,连个手机信号都做不好
最常用的就是各种树形结构的处理,比如本节点可以查看当前节点一直到根节点,当前节点所有子节点的数据之类
你们没想明白
安卓手机电池多少钱?
果子手机电池多少钱?
79 天前
回复了 redbeanzzZ 创建的主题 微信 想在小区建个微信小程序的论坛可行吗?
微信群公告里面写上腾讯文档的地址
下个指环王就 0.5t 了
秦 l dmi 发动机热效率 46%,馈电油耗 4.x, 0-100 加速 7.5 秒,综合续航 2000 公里,算不算遥遥领先?
或者楼主找个更强的出来看看呗
85 天前
回复了 liudewa 创建的主题 汽车 雷车,为什么能把价格打下来
上面说了很多了,小米生态,北京的支持,雷军亲自带队,另外还挖了吉利汽车研究院院长和 20 多个核心
PC 可以配置到 12600k +64g ddr4 +2t nvme ssd ,后期可以看行情再加显卡
86 天前
回复了 ayang23 创建的主题 分享发现 这道数学题能让目前所有 AI 原地爆炸
时间还可以不是整数 ,疏忽了 ,改了下提示:结果是 19.6

import org.apache.commons.math3.fraction.Fraction;

public class WaterPool {

public static void main(String[] args) {
Fraction capacity = new Fraction(1, 1);
Fraction current = Fraction.ZERO;
// 甲、乙、丙的流量分别是 1/5 、1/6 、-1/4
Fraction[] flows = {
new Fraction(1, 5),
new Fraction(1, 6),
new Fraction(-1, 4)
};

int completeHours = 0;
while (current.compareTo(capacity) < 0) {
int index = completeHours % 3;
Fraction rate = flows[index];

// 计算当前水管需要多少时间才能刚好注满
if (rate.compareTo(Fraction.ZERO) > 0) { // 进水管
Fraction timeToFill = capacity.subtract(current).divide(rate);
// 如果需要的时间不超过 1 小时,那么就找到精确时间了
if (timeToFill.compareTo(Fraction.ONE) <= 0) {
System.out.println("最终结果: " + (completeHours + timeToFill.doubleValue()) + " 小时");
return;
}
}
// 否则,完成一个完整小时
current = current.add(rate);
completeHours++;
// 如果水量变为负,重置为 0
if (current.compareTo(Fraction.ZERO) < 0) {
current = Fraction.ZERO;
}
}

System.out.println("需要整数小时数: " + completeHours + " 小时");
}
}
86 天前
回复了 ayang23 创建的主题 分享发现 这道数学题能让目前所有 AI 原地爆炸
1/6 转为浮点有精度丢失,改为 apache 的 Fraction 类

import org.apache.commons.math3.fraction.Fraction;

public class WaterPoolRecalc {
public static void main(String[] args) {
Fraction capacity = new Fraction(1, 1);
Fraction current = Fraction.ZERO;
// 甲、乙、丙的流量分别是 1/5 、1/6 、-1/4
Fraction[] flows = {
new Fraction(1, 5),
new Fraction(1, 6),
new Fraction(-1, 4)
};

int hours = 0;
while (current.compareTo(capacity) < 0) {
current = current.add(flows[hours % 3]);
hours++;
// 如果水量小于 0 则重置
if (current.compareTo(Fraction.ZERO) < 0) {
current = Fraction.ZERO;
}
}

System.out.println("需要的小时数:" + hours); // 输出 20
}
}
86 天前
回复了 ayang23 创建的主题 分享发现 这道数学题能让目前所有 AI 原地爆炸
public class WaterPool {
public static void main(String[] args) {
double capacity = 1.0; // 代表满池
double current = 0.0; // 当前水量
double[] rates = {1.0/5.0, 1.0/6.0, -1.0/4.0}; // 甲、乙、丙每小时进出水比例
int hour = 0;

// 每小时轮流开甲、乙、丙水管
while (current < capacity) {
// 计算当前水管索引
int index = hour % rates.length;
current += rates[index];
hour++;
if (current >= capacity) break;
if (current < 0) current = 0; // 防止出现负值
}

System.out.println("需要的小时数: " + hour);
}
} 结果是 20
1  2  3  4  5  6  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2645 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 55ms · UTC 13:11 · PVG 21:11 · LAX 06:11 · JFK 09:11
Developed with CodeLauncher
♥ Do have faith in what you're doing.