Here is our complete code for the class SquareRoots:
import genesis.*;
public class SquareRoots {
public static void main (String [ ] args) {
double [] squareRoots = new double [10];
for (int i=0; i < squareRoots.length; i++)
squareRoots[i] = Math.sqrt(i+1);
for (int i=0; i < squareRoots.length; i++)
Transcript.println(squareRoots[i]);
}
}
Notice how the expression Math.sqrt(..) is used to evaluate the square roots.
Notice also that as the elements in the array are floating point numbers of type double
and consequently take more space to display, the elements of the array are displayed
on different lines in the Transcript window rather than all on the same line.
Previous Hint