CJCoding With Joseph
15per day

Finally for Resource Cleanup

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
Topics:
Miscellaneous
📥 Auto-Input:
0\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 (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.