← Back to Miscellaneous
Question 151
Format Percent with NumberFormat
Format Percent with NumberFormat
Use Java's NumberFormat class to read a decimal ratio and print it as a percentage with exactly one decimal place. Create a percent formatter withNumberFormat.getPercentInstance(), then set both min and max fraction digits to 1. The formatter multiplies your decimal by 100 and appends % automatically. ⚠️ AUTO-INPUT MODE: The input stream will automatically contain '0.375\n'. Use Scanner'snextDouble()to read it - no keyboard input is needed.
Expected Output:
Rate: 37.5%= 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.