← Back to Exceptions
Question 778
Throw From a Method
Throw From a Method
Read an integernand printResult: <100 / n>using a helper methodDivideHundred(int x)that returns100 / xbut throwsnew DivideByZeroException()whenxis0. Catch the exception in the top-level code and print exactlyCannot divide by zero. Use top-level statements withtry/catch, and declare the helper method after the statements. Input4prints: Result: 25 Input0prints: Cannot divide by zero
Expected Output:
Result: 25= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.