我无法弄清楚为什么我的代码导致 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;
}