Arrays: Print all the elements of an array
Program to print all the elements of an array
Explaination
We will use a for loop to print all the elements.
- Initialize a counter and traverse through the array
- At each iteration, print the element at counter position
Java Code:
int[] elements = {2,5,3,8,5,1};
for(int i = 0; i < elements.length(); i++){
System.out.print(elements[i] + " ");
}
Thanks for feedback.