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.



Read More....
Check if an array is a min heap
Convert a sorted array into a binary search tree - recursive approach
Find the kth largest element in the array
Find the kth smallest element in the array
Merge two sorted arrays