for each element in array do this java code example
Example 1: how to use for loop for array in java
import java.io.*;
class GFG {
public static void main(String args[]) throws IOException
{
int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int i, x;
for (i = 0; i < ar.length; i++) {
x = ar[i];
System.out.print(x + " ");
}
}
}
Example 2: java loop through array
class LoopThroughArray {
public static void main(String[] args)
{
int[] myArr = {1, 2, 3, 4};
for(int i : myArr){
System.out.println(i + "\n")
}
}
}