im writing a program that im using an integer.parseInt, which
needing to convert'String args[]' my code should print:
Index value
0 0
1 0
2 0
3 0
when I call the InitArray from the command via:
It should print:
java InitArray 4.
heres my code any suggestions would be great.
public class InitArray
{
public static void main( String args[] ) {
if ( args.length != 4 )
System.out.println( "java InitArray 4" );
else {
int arrayLength = Integer.parseInt( args[ 0 ] );
int array[] = new int[ 4 ];
int initialValue = Integer.parseInt( args[ 1 ] );
int increment = Integer.parseInt( args[ 2 ] );
for ( int counter = 0; counter < array.length; counter++ )
array[ counter ] = initialValue + increment *
counter;
System.out.printf( "%s%8s\n", "Index", "Value" );
for ( int counter = 0; counter < array.length; counter++ )
System.out.printf( "%5d%8d\n", counter, array[
counter ] );
}
}
}