019-005-005
Resource Management: Using try-with-resources
Medium
Problem Description
Resource Management: Using try-with-resources
Learning Objective: Understand how to automatically close resources using try-with-resources
Use a Resource class implementing AutoCloseable to verify automatic resource closing.
Input
Line 1: Resource name
Line 2: Process type ("success" or "error")
Output
Each line shows processing status:Opening: [name]
On success: Processing: [name]
On error: Error during processing
Finally: Closing: [name]
Example
Input:
MyResource
success
```java
Output:
```java
Opening: MyResource
Processing: MyResource
Closing: MyResource
Test Cases
※ Output examples follow programming industry standards
Input:
MyResource success
Expected Output:
Opening: MyResource Processing: MyResource Closing: MyResource
Input:
TestRes error
Expected Output:
Opening: TestRes Closing: TestRes Error during processing
Input:
Database success
Expected Output:
Opening: Database Processing: Database Closing: Database
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 9 free executions remaining
