// foreach example
public class ForEachLoop {
public static void main(String[] args) {
int arrayname[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21};//learn
for (int val : arrayname) {
System.out.print(" "+val);
}System.out.println();
//explore
for(float val : arrayname){
System.out.print(" "+val);
}System.out.println();
for(double val : arrayname){
System.out.print(" "+val);
}
}}
Output:1 3 5 7 9 11 13 15 17 19 21
1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0 21.0
1.0 3.0 5.0 7.0 9.0 11.0 13.0 15.0 17.0 19.0 21.0
Note: For each loop is used to iterate the items of an array.