11. Program to print the number of elements present in an array
💡Code:
public class NumberOfElementsInArrayp7_7078 {
public static void main(String[] args) {
// Example array
int[] numbers = {15, 7, 23, 45, 9, 56, 82, 31};
// Print the number of elements in the array
int numberOfElements = countElements(numbers);
System.out.println("Number of elements in the array: " + numberOfElements);
}
// Function to count the number of elements in an array
private static int countElements(int[] array) {
return array.length;
}
}
📸Output :