gpt4 book ai didi

java - PrintStream 意外地移至新行?

转载 作者:太空宇宙 更新时间:2023-11-04 15:06:28 26 4
gpt4 key购买 nike

我不明白为什么我的代码导致 PrintStream 转到新行:

// displays the total time of the leak in months from the calculateLeakTime() method. 
String leakTime = LeakCalculator.calculateLeakTime();
System.out.println("The total time of the leak is " + leakTime + " months.");

输出如下所示:

“泄漏总时间为12
几个月。”

我不明白为什么月份会打印在新行上。我什至尝试过这个:

// displays the total time of the leak in months from the calculateLeakTime() method. 
String leakTime = LeakCalculator.calculateLeakTime();
System.out.print("The total time of the leak is " + leakTime);
System.out.println(" months.");

我得到了相同的输出。有人可以解释为什么将“月”移至新线吗?

谢谢

凯文

编辑:这是 calculatLeakTime() 方法:

static String calculateLeakTime() throws ParseException{

long leakEndMili = getLeakEnd();
long leakBeginMili = getLeakBegin();

long timeDays = ((leakEndMili - leakBeginMili) / (1000 * 60 * 60 * 24));

double timeMonths = (double) (timeDays * 0.0328549);

System.out.println(timeMonths);

String monthsRounded = String.format("%.0f%n", timeMonths);

return monthsRounded;
}

最佳答案

从以下行中删除“%n”:

String monthsRounded = String.format("%.0f%n", timeMonths);

关于java - PrintStream 意外地移至新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21924092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com