我不确定原因,但是当我输入此代码时,当我在输入中包含美元符号和逗号时,我会不断收到错误。我只是不断收到一条很长的错误消息,但对于小数,它可以正常工作。
String currencyValue;
System.out.print("Enter a currency value or enter q to quit: ");
currencyValue = stdIn.next();
while (!currencyValue.equalsIgnoreCase("q"))
{
System.out.printf("Formatted currency value: $%,.2f\n", Double.parseDouble(currencyValue));
System.out.print("Enter a currency value or enter q to quit: ");
currencyValue = stdIn.next();