user
Create an efficient algorithm to count the number of elements in an array
Array: [3, 4, 7, 5, 1]

assistant
int count = 0; 
  
for (int i = 0; i < array.length; i++) 
    count++;  
  
// print the total number of elements 
System.out.println("Total number of elements : " + count);