【发布时间】:2020-10-14 06:00:45
【问题描述】:
我正在上我的大学 (Java) 的初学者编程课程,我们的任务是使用 eclipse IDE 将下图中的内容准确地输出到控制台。我想知道如何在购买价格旁边包含“$”字符?如果不把事情搞砸,我无法弄清楚。另外,我想对我的代码以及我可以做些什么来使它更好的任何反馈。谢谢。这是我迄今为止为这项任务所做的:
到目前为止我的代码:
public class PurchaseReport
{
public static void main(String[] args)
{
double shirt=21.99;
double pants=49.97;
double shoes=89.50;
double belt=19.99;
double coat=129.95;
double tot=311.40;
System.out.println("");
System.out.println("----------------------------------");
System.out.println("----------------------------------");
System.out.println("");
System.out.println("Purchase Report");
System.out.println("");
System.out.println("----------------------------------");
System.out.println("----------------------------------");
System.out.println("");
System.out.printf("Shirt: %26.2f%n%n", shirt);
System.out.printf("Pants: %26.2f%n%n", pants);
System.out.printf("Shoes: %26.2f%n%n", shoes);
System.out.printf("Belt: %27.2f%n%n", belt);
System.out.printf("Coat: %28.2f", coat);
System.out.printf("%n%n");
System.out.println("----------------------------------");
System.out.println("----------------------------------");
System.out.println("");
System.out.printf("Total: %27.2f", tot);
}
}
这是我的代码输出到控制台的内容: console output screenshot
【问题讨论】:
-
仍然没有投票或接受有效的答案
标签: java eclipse debugging console printf