5.write a program to print elements of an array
💡Code:
public class Singledimensionp2_7078 {
public static void main(String[] args) {
// Example array
int[] numbers = {1, 2, 3, 4, 5};
// Print elements of the array
System.out.println("Elements of the array:");
printArray(numbers);
}
// Function to print elements of an array
private static void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
}
📸Output :