0

I use a buffered reader to read in the input and then it adds it to an array. But for some reason it only adds the last input to the array. I also want to check if the first input is zero... so thats what I am doing with the check variable. But the main problem is that it doesn't add it to the array.

public static void main (String[] Args) throws IOException
{
    int[] numbers = new int[100];

    Scanner scan = new Scanner(System.in);
    InputStreamReader isReader = new InputStreamReader(System.in);
    BufferedReader bReader;
    bReader = new BufferedReader(isReader);
    int intNumber = Integer.parseInt(bReader.readLine());
    int check = scan.nextInt();
    while (check != 0)
    {
        int i = 0;
        numbers[i] = Integer.parseInt(bReader.readLine());
        check = intNumber;
        i++;
    }
    bReader.close();
}
Ryan C
  • 3
  • 1
  • 3

1 Answers1

3

move int i = 0 outside of while loop. In each iteration i is getting initialized to 0 so your array is having only one value and that is in 0th index

Rahman
  • 3,755
  • 3
  • 26
  • 43