Question: Problem #6 What is wrong with the following code to initialize an array b? int[ ] b = new int[10]; int i; for (i =

Problem #6 What is wrong with the following code to initialize an array b?

int[ ] b = new int[10];

int i;

for (i = 1; i <= b.length; i++)

b[i] = 5*i;

Problem #2 Describe the common error in the following code.

Arrays may be instance variables as follows:

private int[ ] scores;

The scores are read-only from outside the class; therefore, we will provide a getter method but no setter method as follows:

public int[ ] getScores() {

return scores;

} // end of getScores

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!