First loop is done using "for each" statement.
Second loop is done using "for" statement.
package p_2013_04_03; public class MyLoop { //Examples of iterating through an arrays public static void main(String[] args) { int[] myTable = {1,2,4,7,44,56,44}; // for each loop in java for( int x : myTable ) { System.out.println( x ); } // Another way of iterating through an array for(int i=0; i < myTable.length; i++) { System.out.println( myTable[i] ); } } }
No comments:
Post a Comment