So, im new in Java and i would like to fill an ArrayList with integers form keyboard but after i run the code and give one number it gives me exceptions. What am i missing ?
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int j=0,x=0;
ArrayList<Integer> numb = new ArrayList<Integer>(5);
Scanner scanner = new Scanner(System.in);<br>
System.out.println("Give numbers to the array:");<br>
for(j=0;j<=5;j++)
{
System.out.println("Give the "+j+"st item of the list");
x = scanner.nextInt();
numb.set(j, x);
}
System.out.println("\nThe array is:");
for(Integer i:numb)
System.out.println(i);
}
}