Thanks for the help, and I do have questions. The homework assignment was to rewrite the original code so that the array size is specified by the first command-line arg, but if none was given to default the size to 10. So, I was originally prompting for user input to specify the size of the array they wanted, but I think that I just was confused on what I needed to do... and I'm still a bit unclear. I started all over, thinking it would help, but I still don't entirely get it. The output of the original file is below as well as my new code. Can someone please help steer me in the right direction?
Original file output:
Index Value
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
My new code:
|
Code:
|
public class InitArrayNew2
{
public static void main( String args[] )
{
// check number of command-line arguments
if (args.length !=10 )
{
I'm not sure what to do here
}
else
{
// get array size from first command-line argument
int arrayLength = Integer.parseInt( args[ 0 ]);
int array[] = new int[ arrayLength ]; // create the space for array
// get initial value and increment from command-line arguments
int initialValue = Integer.parseInt( args[ 1 ]);
int increment = Integer.parseInt( args[ 2 ] );
}
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 InitArrayNew2 |