-4

So for some reason compiler keeps saying that the "input" is never closed. However, the program runs and executes. I just want to know why it keeps saying it. Here is the syntax. Thanks in advance.

import java.util.Scanner;
public class Problem1 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter three numbers: ");
        int N1 = input.nextInt();
        int N2 = input.nextInt();
        int N3 = input.nextInt();       
        DoSort(N1, N2, N3);


    }
    public static void DoSort(int N1, int N2, int N3){

        if ((N1 < N2) && (N2 < N3)){
            System.out.println("The acsending order is " + N1 + " " + N2 + " " + N3);
            }
        if ((N1 > N2) && (N2 > N3)){
            System.out.println("The acsending order is " + N3 + " " + N2 + " " + N1);
            }
        if ((N1 < N2) && (N2 > N3) && (N1 < N3)){
            System.out.println("The acsending order is " + N1 + " " + N3 + " " + N2);
            }
        if ((N1 < N2) && (N2 > N3) && (N1 > N3)){
            System.out.println("The acsending order is " + N3 + " " + N1 + " " + N2);
            }

        }
    }

enter image description here

Srikanth Balaji
  • 2,638
  • 4
  • 18
  • 31
  • 2
    Because you don't close it? You can close it with input.close() after you are done getting the input. – Janar Feb 28 '17 at 08:38
  • try something like `try (Scanner input = ....) { //block of code }` if you are using JDK 7 or above. – SMA Feb 28 '17 at 08:40
  • Note: your `DoSort` logic doesn't consider the case that some of the numbers are equal. – Andy Turner Feb 28 '17 at 08:45

1 Answers1

1

This is just a warning that unfortunately does not apply in your case, because you really don't want to close System.in.

Add a @SuppressWarnings("resource") before the line (it should be a quick fix as well) to get rid of the warning.

john16384
  • 7,800
  • 2
  • 30
  • 44