package hw6;
import java.util.Scanner;
import java.util.ArrayList;
public class hw6q1 {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<Integer>();
Scanner input = new Scanner(System.in);
System.out.println("Enter integers between 1 and 100 (enter 0 to
stop):");
while(input.nextInt() != 0){
al.add(input.nextInt());
}
input.close();
for(int i = 0; i < al.size(); i++){
System.out.println(al.get(i));
}
}
}
So that is my code and when I run the program and give in the numbers 1 2 3 4 then 0 to end the loop it only prints 2 and 4. I was wondering why that is the case and how to fix it so that the arraylist gets all the number 1 2 3 and 4.