urgent help today - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

urgent help today

Pete1972Pete1972 Posts: 24Member
I have an assignment due and i cannot get this to work.

public class InitArray
{

public static void main( String args[ ] )
{
// check number of command-line arguments
if ( args.length != 3 )
System.out.println(
"Error: Please re-enter the entire command, including
" +
"an array size, initial value and increment." );
else
{
// get array size from first command-line argument
int arrayLength = Integer.parseInt( args[ 0 ] );
String args1[] = new String[ arrayLength ]; // create array

// get initial value and increment from command-line argument
double initialValue = Double.parseDouble( args[ 1 ] );
double increment = Double.parseDouble( args[ 2 ] );

double total = 0.0;

for ( String argument : args1 )
total = total + Double.parseDouble( argument ) * initialValue + increment;

System.out.printf( "The sum of the values in the array are %f", total );
}

} // end main

} // end class

i have to use the enhanced for statement to calculate the sum of the array. the values are passed using the command-line. here is the error message that i get.

C:Java>java InitArray 3 1 5
Exception in thread "main" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at InitArray.main(InitArray.java:32)

any help would be appreciated. thanks.

Comments

Sign In or Register to comment.