public static void addVectors ( double [ ] a1 , double [ ] a2 ) { assert ( a1 != null ) ; assert ( a2 != null ) ; assert ( a1 . length == a2 . length ) : "Adding two arrays of different " + "length" ; for ( int i = 0 ; i < a1 . length ; i ++ ) { a1 [ i ] += a2 [ i ] ; } }
Adds the second array to the first array element by element . The arrays must have the same length .