CJCoding With Joseph

Catch Divide By Zero

Read two integers a and b (each on its own line) and print a / b. If b is 0, catch the DivideByZeroException and print Error: cannot divide by zero. Use top-level statements with try/catch.

Input 10 then 2 prints: 5
Input 10 then 0 prints: Error: cannot divide by zero

Expected Output:

5
Topics:
Exceptions
๐Ÿ“ฅ Auto-Input:
10\n2\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.