Question: I have an error in this code and cannot figure why. public class PrintArray extends ConsoleProgram { public void run() { int[] array = makeArray(10);

I have an error in this code and cannot figure why.

public class PrintArray extends ConsoleProgram

{

public void run()

{

int[] array = makeArray(10);

printArray(array);

int[] ages = makeArray(-3);

printArray(ages);

}

public int[] makeArray(int length)

{

if(length < 0)

{

return null;

} else {

int[] res = new int[length];

for(int i = 0; i < length; i++)

{

res[i] = i;

}

return res;

}

}

public void printArray(int[] arr)

{

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

{

System.out.print(arr[i] + ", ");

}

System.out.println();

}

}

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 Programming Questions!