214k views
3 votes
Write the definition of a function printArray, which has two parameters. The first parameter is an array of integers and the second is an int, the number of elements in the array. The function does not return a value. The function prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.

1 Answer

4 votes

Answer:

public static void printArray(int [] intArray, int elements){

for(int i =0; i<intArray.length; i++){

System.out.println("The element "+(i+1)+" is "+intArray[i]);

}

}

A complete java program with a call to the method printArray() is given in the explanation section

Step-by-step explanation:

public class ArrayPrinting {

public static void printArray(int [] intArray, int elements){

for(int i =0; i<intArray.length; i++){

System.out.println("The element "+(i+1)+" is "+intArray[i]);

}

}

public static void main(String[] args) {

//Declare and initialize an Array

int [] newArray = {10,11,12,13,14,15,16,17,18,19,20};

//Call the method printArray()

printArray(newArray,10);

}

}

User Matthew I
by
5.8k points