Why am I getting an exception?

丶灬走出姿态 提交于 2019-12-02 05:46:35

A: Because your format specifiers don't match input arguments used in the printf method.

Use %f rather than %d as the format specifier character for double values

System.out.printf("Diamond Cost: $%,.2f \n", diamondCost); 
                                      ^

In addition % requires an additional % to escape that character

System.out.printf("State Tax @ 10%%: $%,.2f \n", stateTax);

Finally, remove the unnecessary dot character

System.out.printf("Number Ordered: $%,.2d \n", numOrdered);
                                      ^

Read: Formatter javadoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!