Parse int with fallback
Java
Easy
7 views
Problem Description
Task: parse integer from string; if invalid, return fallback value.
Output Format
Return value
Constraints
Use try/catch for NumberFormatException.
Official Solution
static int parseOrDefault(String s,int fallback){try{return Integer.parseInt(s);}catch(NumberFormatException e){return fallback;}}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!