CJCoding With Joseph

Catch a Divide By Zero

Read two integers a and b (one per line), then print the result of a / b. If b is 0, dividing throws a DivideByZeroException — catch it and print exactly Cannot divide by zero. Use top-level statements with try/catch.

Input 10 then 2 prints: 5
Input 10 then 0 prints: 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.