CJCoding With Joseph

Throw From a Method

Read an integer n and print Result: <100 / n> using a helper method DivideHundred(int x) that returns 100 / x but throws new DivideByZeroException() when x is 0. Catch the exception in the top-level code and print exactly Cannot divide by zero. Use top-level statements with try/catch, and declare the helper method after the statements.

Input 4 prints: Result: 25
Input 0 prints: Cannot divide by zero

Expected Output:

Result: 25
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
4\n
This input is automatically fed to your program's stdin
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.