Task: parse integer from string; if invalid, return fallback value.
• First line: A String s
• Second line: An integer fallback
• Print one integer:
• Parsed integer if the string is valid
• Otherwise, fallback value
• -10^9 ≤ parsed integer ≤ 10^9
• -10^9 ≤ fallback ≤ 10^9
• 0 ≤ length of string ≤ 100
The string "12a3" contains a letter (a).
So it is not a valid integer.
Therefore, we return the fallback value.
• Read string s using Scanner.
• Read integer fallback.
• Use Integer.parseInt(s) inside a try block.
• If parsing is successful, print the parsed value.
• If NumberFormatException occurs, print the fallback value.