189k views
4 votes
Read an integer as the number of lion objects. Assign mylions with an array of that many lion objects. For each object, call the object's read() followed by the object's print().

Ex: If the input is 2 5 336 4 272, then the output is:

User Luigj
by
7.8k points

1 Answer

4 votes

Final answer:

The student is asked to read and print information about a number of lion objects using an array. This can be done by using a loop to iterate over the array and call the read() and print() methods for each lion object.

Step-by-step explanation:

In this question, the student is asked to read and print information about a number of lion objects using an array. To do this, we can use a loop to iterate over the array and call the read() and print() methods for each lion object. Here is an example:



// Read the number of lion objects
int numLions = scan.nextInt();

// Create the array of lion objects
Lion[] mylions = new Lion[numLions];

// Loop through the array and initialize each lion object
for (int i = 0; i < numLions; i++) {
mylions[i] = new Lion();
mylions[i].read();
mylions[i].print();
}



This code assumes that there is a Lion class with read() and print() methods that read and print information about a lion object.

User Flyingfinger
by
7.9k points