public class Practice 7 {
public static void main(String[]args) {
int num1 = new java.util.Scanner(System.in).nextInt();
int num2 = new java.util.Scanner(System.in).nextInt();
System.out.println(num1+num2);
}
}
I type num1 and num2 on the keyboard and enter the code for the sum.
Yellow to the left of the two lines int num1=... and int num2=...!Marked and light volves,
If you take the cursor over there, it says, "Resource leak '<Unassigned Closeable Value>' will never close."
I don't know what's wrong and I don't understand this resource... so I'd appreciate it if you could let me know m__m
java
I think it's a message to Scanner that the close method is not called.
Can I get that message with the code below?
public static class Practice 7 {
public static void main(String[]args) {
Scanner scanner = new java.util.Scanner (System.in);
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
scanner.close();
System.out.println(num1+num2);
}
}
Also, Scanner implements AutoClosable, so if it is Java 7 or later, it can be closed using try-with-resource writing.
543 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
680 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
544 PHP ssh2_scp_send fails to send files as intended
524 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.