CJCoding With Joseph
15free / daySign inCreate account

Read two integers and print Result: <Divide(a, b)>. Write a local function int Divide(int x, int y) that throws new DivideByZeroException("cannot divide by zero") when y is 0, and otherwise returns x / y. Catch that exception in the caller and print its message. Use top-level statements (declare the local function at the end).

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

Expected output

Result: 5

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
Exceptions
Auto-input
10\n2\n
This input is automatically fed to your program's stdin
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.