/*print array elements using for loop in java*/
public class Test {
public static void main(String args[]){
int y,numbers[] = {10, 20, 30, 40, 50};
for(int x=0 ; x<5;x++ ){
y=numbers[x];
System.out.println( y );
}
}
}
public class Test {
public static void main(String args[]){
int y,numbers[] = {10, 20, 30, 40, 50};
for(int x=0 ; x<5;x++ ){
y=numbers[x];
System.out.println( y );
}
}
}
● Save the file as Test.java.
Output:
>java Test
10
20
30
40
50