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
Get step-by-step solutions from verified subject matter experts
