如何将小数点更改为冒号?
How can I change the decimal to a colon?
Without changing the code, how would I be able to change the output from being 13.00 to 13:00? Is it possible to do so in the printf string?
System.out.print("Please enter the current hour on the clock(no minutes): ");
double time = sc.nextDouble();
System.out.print("Please enter the duration in hours: ");
int duration = sc.nextInt();
double newTime = (time+duration)-24;
System.out.println();
System.out.printf("If it is %.2f, in %d hours, it will be %.2f.\n",time,duration,newTime);
我建议替换“.”到“:”作为 stand-alone 行。我不明白你为什么要在 printf 中这样做。尽管如此,这里有一个如何做到这一点的例子
System.out.printf("If it is %s.\n", String.valueOf(time).replace(".",":"));
本质上是将双精度数转换为字符串,然后替换字符。
另外,记得更改 %s 标签。
Without changing the code, how would I be able to change the output from being 13.00 to 13:00? Is it possible to do so in the printf string?
System.out.print("Please enter the current hour on the clock(no minutes): ");
double time = sc.nextDouble();
System.out.print("Please enter the duration in hours: ");
int duration = sc.nextInt();
double newTime = (time+duration)-24;
System.out.println();
System.out.printf("If it is %.2f, in %d hours, it will be %.2f.\n",time,duration,newTime);
我建议替换“.”到“:”作为 stand-alone 行。我不明白你为什么要在 printf 中这样做。尽管如此,这里有一个如何做到这一点的例子
System.out.printf("If it is %s.\n", String.valueOf(time).replace(".",":"));
本质上是将双精度数转换为字符串,然后替换字符。 另外,记得更改 %s 标签。