public class array_basics { public static void main(String[] args) { int[] x = new int[3]; // draw boxes x[0] = 2; x[1] = 4; x[2] = 6; // x[3] = __ <- common mistake // revise boxes! print(x); } public static void print(int[] v) { for(int i=0 ; i<v.length ; i++ ) // or say i<=v.length-1 System.out.print(v[i] + " "); System.out.println(); // why need this? } } /* output: */