Hope you are doing well.
The warning is due to scanner sc is not closed so at the end of the code add sc.close(); the warning will be removed.
Few details about the warning:
Classes implementing the interface java.io.Closeable (since JDK 1.5) and java.lang.AutoCloseable (since JDK 1.7) are considered to represent external resources, which should be closed using method close(), when they are no longer needed.
The JDK defines a few classes which implement Closeable but do not
directly represent a resource at the level of the operating system.
java.io.StringReader is an example of a closeable that doesn't require calling close() because no operating system resources are held that would require clean-up. The analysis uses an explicit white list to detect classes from java.io that fall in this category. No resource leak warnings are issued regarding these classes.
Instances of classes like java.io.BufferedInputStream are wrappers around another resource (where wrappers can be applied at multiple levels). Also these objects do not directly represent an operating system resource. If the wrapped resource is closed, the wrapper doesn't need closing. Conversely, if a wrapper is closed this will include closing of the wrapped resource. The analysis has a second white list for detecting wrapper resources, and will recognize whether the underlying actual resource will be closed directly or indirectly via the wrapper.
You can always ignore this warning it wont affect the program in any ways.
I hope this resolves your query.
If you face any further issue kindly let us know.
We will be glad assisting you.