-1
public class ArrayReversal {
    public static void main(String[] args) {
        double[] numbers = readInputs(5);
        printReversed(numbers);
    }

    public static double[] readInputs(int numberOfInputs) {
        System.out.println("Enter " + numberOfInputs + "numbers: ");
        Scanner in = new Scanner(System.in);
        double[] inputs = new double[numberOfInputs];
        for (int i = 0; i < inputs.length; i++) {
            inputs[i] = in.nextDouble();
        }
        return inputs;
    }

    public static void printReversed(double[] values) {
        for(int i = values.length - 1; i>= 0; i--) {
            System.out.print(values[i] + " ");
        }
    }
    //in.close();
}

i have close() commented because it was giving me a syntax error saying an identifier is expected. So i'm not sure where to put it.

ceejayoz
  • 165,698
  • 38
  • 268
  • 341

1 Answers1

2

'in' is never closed warning

So close it.

 public static double[] readInputs(int numberOfInputs) {
        System.out.println("Enter " + numberOfInputs + "numbers: ");
        Scanner in = new Scanner(System.in);
        double[] inputs = new double[numberOfInputs];
        for (int i = 0; i < inputs.length; i++) {
            inputs[i] = in.nextDouble();
        }
        //be aware: you are globally closing System.in
        in.close();
        return inputs;
    }
FMiscia
  • 223
  • 1
  • 10
  • 1
    Please be aware that this will close `System.in` which is fine as long as you are never going to read from `System.in` again in the application. – CollinD Nov 01 '16 at 19:53