Package edu.cnm.deepdive
Class Generator
java.lang.Object
edu.cnm.deepdive.Generator
public class Generator extends Object
Defines the
oscillatingSquares(int)
method, which constructs an array of values of
alternating signs. Implementation of this method is included as a practical exam problem of the
Deep Dive Coding Java training programs.-
Method Summary
Modifier and Type Method Description static int[]
oscillatingSquares(int length)
Creates and returns anint[]
containing a sequence of alternating positive and negative squared values, of the form (-1)nn2, where n = 0…(length - 1)
.
-
Method Details
-
oscillatingSquares
public static int[] oscillatingSquares(int length)Creates and returns anint[]
containing a sequence of alternating positive and negative squared values, of the form (-1)nn2, where n = 0…(length - 1)
.For example,
Generator.oscillatingSquares(5)
returns an array containing the values{0, -1, 4, -9, 16}
.- Parameters:
length
- Number of elements in array.- Returns:
- Generated array of oscillating squares.
-