Answer:
public class ArrayTest {
public static void main(String[] args) {
int [ ] inventoryArray = {2,34,45,65,78,78,100};
Array obj = new Array();
obj.printArray(inventoryArray);
//new Array().printArray(inventoryArray);
}
}
class Array {
public void printArray(int []arr) {
for(int i =0; i<arr.length; i++){
System.out.print(arr[i]);
System.out.print(" ");
}
}
}
Explanation:
- Two classes are created
- Array and ArrayTest
- The class Array has the method printArray that accept an argument array and prints the contents using a for loop.
- In the class ArrayTest, and array is created and initialized with some values called inventoryArray.
- An object of the Array class is created and named obj
- the method printArray of the Array class is called and passed the created inventoryArray. This prints the values to the screen