[SOLVED] Errors with project: specify array size by the value in first command-line a
I need assistance with a homework assignment. The project was to rewrite an existing textbook example so that the array size is specified by the value in the first command-line arg. Here is the code. It giving errors for lines 21, 25, 28, 29, 32, but I can't figure out why. Can someone please help me debug the cause of the errors?
Code:
import java.util.Scanner; // program uses class Scanner
public class InitArrayNew
{
public static void main( String args[] )
{
int array[]; // declare array named array
int inputNumber = 0; // number value entered
array = new int[ inputNumber ]; // create the space for array
// prompt for user to input a number for the array size
System.out.println( "Please enter a number for the array size: " );
int num = input.nextInt();
// validate the input
if (inputNumber > 0)
array[length] = array[num];
}
else
{
array[length] = array[10];
}
System.out.printf( "%s%8s\n", "Index", "Value" ); // column headings
// output each array element's value
for ( int counter = 0; counter < array.length; counter++ )
System.out.printf( "%5d%8d\n", counter, array[ counter ] );
} // end main
} // end class InitArrayNew