2016-09-17 18 views
-4

好吧,所以我似乎无法得到变量“mChoc”和“fChoc”在“你应该吃”和“巧克力棒,如果你是男性/女性的同一行保持你的体重。“我可以得到一些帮助吗?我一直在阅读我的教科书,而且似乎找不到解决方案。我需要保持的"%1.2f"如何让两个数字和文字在同一行

System.out.println("\nYou should eat "); 
System.out.printf ("%1.2f", mChoc); 
System.out.println(" chocolate bars if you are male to maintain your weight!"); 

System.out.println("You should eat"); 
System.out.printf("%.2f", fChoc); 
System.out.println(" chocolate bars if you are female to maintain your weight!"); 
+2

JavaScript代码来似乎是错误的。 – ASDFGerte

+0

这是非常奇怪的JavaScript ......你可能应该使用'console.log' ......如果是在你提出关于SO的问题之前,你需要使用每种方法的Java阅读文档。 –

回答

3

使用print而不是println(第二增加了一个新行),你可以使用一个调用,比如

System.out.printf("You should eat %.2f chocolate bars if " 
     + "you are female to maintain your weight!%n", fChoc); 
相关问题