CJCoding With Joseph
15free / daySign inCreate account

Simulate opening and closing a database connection. Write a program that: 1. Prints "Connection opened" 2. Reads an integer and divides 100 by it, printing "Result: X" 3. Catches ArithmeticException and prints "Query failed" 4. Always prints "Connection closed" at the end — even if an exception occurred

Use try-catch-finally. Print "Connection opened" before the try block.

⚠️ AUTO-INPUT MODE: The input stream will automatically contain '0\n'.

Expected output

Connection opened
Query failed
Connection closed

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

Hints4 available
Topics
Miscellaneous
Auto-input
0\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 (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.