I am getting an error when I initialize the Scanner: the code turns italic and blue as soon as I type a semicolon.
The error message says:
Resource leak: 'in' is never closed.
How can I avoid this error?
My code looks like this:
import java.util.Scanner;
public class Zoezi9 {
public static void main(String[] args) {
double cm;
int feet, inches, remainder;
final double CM_PER_INCH = 2.54;
final int IN_PER_FOOT = 12;
Scanner in = new Scanner(System.in);
System.out.print("How many cm?; ");
cm = in.nextDouble();
inches = (int) (cm/CM_PER_INCH);
feet = inches/IN_PER_FOOT;
remainder = inches % IN_PER_FOOT;
System.out.printf("%.2f cm = %d ft, %d in\n",cm,feet,remainder);
}
}