2014-10-28 6 views
0

어쨌든 나는 무식하게 들린다. 이것은 Java를 배우는 첫날입니다. 문제가 있습니다. 프로그램을 실행할 때마다.Eclipse에서 Java 용 콘솔 텍스트의 공간을 알아내는 방법을 아는 사람이 있습니까?

Eveytime 프로그램을 실행하면 "53308.0of Drew Brees의 패스 야드 is533.08Football 필드"라고 읽습니다. 숫자 "53308.08"과 "of"와 "533.08"사이에 공백을 넣는 방법을 모르겠다. 콘솔 텍스트가 어떻게되어야 하나? 내가 고칠 수 있을까? 문자열에 필요한 경우

공용 클래스 BreesPassingYardsFields { 공공 정적 무효 메인 (문자열 인수 []) {

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"); 

} 

}

답변

2

가장 간단한 방법은 다음과 같습니다 : 당신이 텍스트에서 그것을처럼

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

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

그냥 공백을 추가합니다.

0

" 사이에 원하는 공백을 채울 수 있습니다.

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

것은 그들을 넣어

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의 형식이고, % d를 사용하는 int의 경우 % .3f와 같은 몇 가지 옵션으로 숫자의 서식을 지정할 수 있습니다. http://docs.oracle.com/javase/tutorial/java/data/numberformat.html