Enhanced For Loop in Java
In Java, there is another form of for loop (notwithstanding standard for loop) to work with arrays and collection, the enhanced for loop.On the off chance that you are working with arrays and collections, you can utilize elective syntax of for loop (an enhanced form of for loop) to iterate through things of arrays/collections. It likewise alludes with respect to each loop in light of the fact that the loop iterates through every component of array/collection.
Java Program To Implement Enhanced For Loop
class Enhanced
{
public static void main(String[] args)
{
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
int sum=0;
System.out.print("Elements in the array : ");
for(int n:numbers)
System.out.print(n + " ");
System.out.println();
for(int n:numbers)
sum=sum+n;
System.out.println("Sum of elements in array : " + sum);
}
}
Output:
Elements in the array : 1 2 3 4 5 6 7 8 9 10
Sum of elements in array : 55
tags : java , java program , java tutorialspoint , tutorialspoint , c ,program of c ,c++ , programs of c++ , code camp , learn java