gpt4 book ai didi

java - 有谁知道如何在 Eclipse 中为 java 分隔控制台文本

转载 作者:行者123 更新时间:2023-12-02 05:19:25 26 4
gpt4 key购买 nike

如果我听起来无知,请原谅。这是我学习 Java 的第一天,我遇到了一个问题。每次我运行一个程序。发生这种情况:

每次我运行程序时,它都会显示“53308.0of Drew Brees' Pass Yards is533.08Football Fields”。我不知道如何在数字“53308.08”和“of”以及“533.08”和足球之间添加空格控制台文本应该是这样的吗?我可以修复它吗?

公共(public)类 BreesPassingYardsFields { 公共(public)静态无效主(字符串参数[]){

double PassYards; // Number of career pass yards Drew Brees has.
double FieldLength; // Number of yards in a football field
double FootballFields; // The amount of football fields Drew Brees has thrown for

PassYards = 53308; // Start with Drew Brees' Pass Yards
FieldLength = 100; // Length of a football field
FootballFields = PassYards / FieldLength; // converts to how many Football Fields Drew Brees has thrown for

System.out.println(PassYards + "of Drew Brees' Pass Yards is" + FootballFields + "Football Fields");

}

}

最佳答案

最简单的方法是:

System.out.println(PassYards + " of Drew Brees' Pass Yards is" + FootballFields + " Football Fields");

或者你可以这样做:

System.out.format("%f of Drew Brees' Pass Yards is %f Football Fields", PassYards, FootballFields);

%f 是 double nad float 的格式,对于 int 您将使用 %d,您可以使用一些选项(如 %.3f 等)格式化数字。请参阅此 http://docs.oracle.com/javase/tutorial/java/data/numberformat.html

关于java - 有谁知道如何在 Eclipse 中为 java 分隔控制台文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26615348/

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