Hi guys
Getting a strange error when I build this program using the Eclipse IDE
(Using Java version 8). I do not understand why I am getting an error -
the book I use does not even explain about this. I might add this is the first
program I have written using the Scanner utility.
The error is:
java Error at line 7: Resource Leak: 'input' is never closed
I have posed all the code, as I have no idea where the problem is.
Thanks very much for any help!
Wishes Ada xx
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num1 = 0; // first number int num2 = 0; // second number int num3 = 0; // third number int num4 = 0; // fourth number int num5 = 0; // fifth number int positive = 0; // number of positive inputs int negative = 0; // number of negative inputs int zero = 0; // number of zero inputs System.out.print("Enter an integer: "); num1 = input.nextInt(); System.out.print("Enter an integer: "); num2 = input.nextInt(); System.out.print("Enter an integer: "); num3 = input.nextInt(); System.out.print("Enter an integer: "); num4 = input.nextInt(); System.out.print("Enter an integer: "); num5 = input.nextInt(); input.close(); // count number of positive numbers if (num1 > 0) positive = positive + 1; if (num2 > 0) positive = positive + 1; if (num3 > 0) positive = positive + 1; if (num4 > 0) positive = positive + 1; if (num5 > 0) positive = positive + 1; // count number of negative numbers if (num1 < 0) negative = negative + 1; if (num2 < 0) negative = negative + 1; if (num3 < 0) negative = negative + 1; if (num4 < 0) negative = negative + 1; if (num5 < 0) negative = negative + 1; // count number of zero values if (num1 == 0) zero = zero + 1; if (num2 == 0) zero = zero + 1; if (num3 == 0) zero = zero + 1; if (num4 == 0) zero = zero + 1; if (num5 == 0) zero = zero + 1; System.out.println("Positives: " + positive + "\nNegatives: " + negative + "Zero-based: " + zero); } }