// exj4.java example file iteration, loops public class exj4 // class name same as file name { public exj4() // constructor same as class name { System.out.println("exj4.java running"); int i; // declare loop variable int mat[][] = {{1,2,3},{2,3,4},{3,4,5},{4,5,6}}; // 4 by 3 matrix int sum = 0; for(i=0; i<4; i++) // columns of mat { // the } could be at end of previous line for(int j=0; j<3; j++) // j only exists inside loop { sum += mat[i][j]; } // end j optional comment } // end i optional comment System.out.println("sum="+sum); for(i=2; i<=10; i=i+2) { System.out.println("i="+i); // even numbers } } // end constructor exj4 // optional comment public static void main (String[] args) { new exj4(); } } // end class exj4 optional comment