[英]Does anyone know how to space out console text for java in Eclipse
Excuse me if I sound ignorant in anyway. 无论如何我都无知。 This is my first day learning Java and I have a problem.
这是我学习Java的第一天,但我遇到了问题。 Everytime I run a program.
每次我运行一个程序。 This happens :
有时候是这样的 :
Eveytime i run my program, it reads "53308.0of Drew Brees' Pass Yards is533.08Football Fields." Eveytime我运行我的程序,它显示为“ Drew Brees的过关区的53308.0是533.08足球场”。 I don't know how to put spaces between the number "53308.08" and "of " and also " 533.08" and Football Is this how console text is supposed to be?
我不知道如何在数字“ 53308.08”和“ of”之间以及“ 533.08”和Football之间放置空格。这应该是控制台文本吗? Can i fix it ?
我可以解决吗?
public class BreesPassingYardsFields { public static void main (String args []) { 公共类BreesPassingYardsFields {public static void main(String args []){
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");
}
} }
The simplest way is: 最简单的方法是:
System.out.println(PassYards + " of Drew Brees' Pass Yards is" + FootballFields + " Football Fields");
or you can do something like this: 或者您可以执行以下操作:
System.out.format("%f of Drew Brees' Pass Yards is %f Football Fields", PassYards, FootballFields);
%f is format for double nad float, for int you would use %d, you can format the number with some options like %.3f etc. see this http://docs.oracle.com/javase/tutorial/java/data/numberformat.html %f是double nad float的格式,对于int来说,您将使用%d,可以使用%.3f等一些选项设置数字的格式。请参见此http://docs.oracle.com/javase/tutorial/java/data /numberformat.html
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.println(PassYards + " of Drew Brees' Pass Yards is " + FootballFields + " Football Fields");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.