← Back to Miscellaneous
Question 165
NumberFormat Parse and Reformat
NumberFormat Parse and Reformat
Read a comma-formatted number string, parse it back to a numeric value with NumberFormat, then reprint it with exactly 2 decimal places. Usesc.nextLine()to read the string, thenNumberFormat.getNumberInstance(Locale.US).parse(text)to convert it.parse()returns a Number object - call .doubleValue()to get a double. The method throws ParseException so main needs throws Exception. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain '12,345.6\n'. Usesc.nextLine()to read it.
Expected Output:
Parsed: 12345.60= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Miscellaneous
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.