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] + " ");
}

 

### Complexity Analysis * **Time Complexity**: O(N) where N is total elements. * **Space Complexity**: O(1).

Share Your Thoughts

Read More

Minimum number of merge operation to make an array palindrom
Find the duplicate value in an array
Find the minimum element in a sorted and rotated array
Merge overlapping Intervals
Find the kth largest element in the array
Browse all Arrays articles

Stay Ahead

Only insights that save you time or money. No fluff.