← 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. Expected Output: Rate: 37.5% Create a percent formatter with NumberFormat.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's nextDouble() to read it - no keyboard input is needed.
Expected Output:
Rate: 37.5%
Topics:
Miscellaneous
Code Editor
1
Tab to indent · Ctrl+Enter to run · 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.