This is probably something everybody knows already, which is why I haven't been able to find the answer anywhere, but here goes anyway.
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
OR
int n = new Scanner(System.in).nextInt();
I recently found out that Scanners need to be "closed" after you finish using them.
However, I have almost always instantiated my Scanners "on the fly" without creating a dedicated object, so I can't really close them.
I thought this was something the garbage collector handled.
Is this a bad practice?