简体   繁体   English

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

[英]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.

相关问题 有谁知道如何在 java(netbeans) 的 textFields 中给出提示文本? - does anyone know how to give a hint text in textFields in java(netbeans)? 控制台用尽了Java堆空间内存,但是Eclipse的设置不相同 - Console runs out of java heap space memory, but Eclipse does not with same settings 在 eclipse 中输入年龄后,我无法编译 rest,它在控制台上显示“已终止”。 有谁知道如何解决这个问题? 谢谢 - I can't compile the rest after inputed the age in eclipse, it says "Terminated" on console. Does anyone know how to solve the problem ? Thanks 有谁知道如何摆脱这个日食错误窗口? - Does anyone know how to get rid of this eclipse error window? 有谁知道java2d文本库? - Does anyone know of a java2d text library? 有谁知道近似的文本像素比? (Java字符串定位) - Does anyone know an approximate text to pixel ratio? (Java String positioning) 有谁知道是否有一个eclipse插件可以指出pom.xml中不兼容的jar? - Does anyone know if there is an eclipse plugin can point out incompatible jars in pom.xml? 使用Java分隔控制台文本而没有选项卡 - Space out console text without tabs using Java 有谁知道如何解析这样的文本文件? - does anyone know how to parse text file like this? 有谁知道如何将这一行 Java 代码翻译成 Python? - Does anyone know how to translate this single line of Java code into Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM