camelCase to CONSTANT_CASE
Mediumjava
Convert a camelCase identifier to the CONSTANT_CASE style used for Java constants: insert an underscore before each interior capital letter, then upper-case everything.
Input: one token in camelCase (letters and digits, first letter lowercase).
Output: one line — the CONSTANT_CASE form.
Example 1
Input
maxRetryCount
Output
MAX_RETRY_COUNT
- 1 <= length <= 60
Hint 1
For each character after the first, if it is upper-case, append '_' before it.
Hint 2
Append the upper-cased character each time.
Hint 3
Character.isUpperCase and Character.toUpperCase do the work.
This is the naming convention constants use. Walk the characters: before any capital letter that is not the first character, add an underscore; then upper-case every character as you append it.