Arrays- Square root of an Array and printing the result JAVA
Posted
by roger34
on Stack Overflow
See other posts from Stack Overflow
or by roger34
Published on 2010-05-31T19:31:56Z
Indexed on
2010/05/31
19:53 UTC
Read the original article
Hit count: 289
Hello,
The title says it all, really. I'm trying to get an array of (9) numbers squared then printed but I keep coming back with only one result - the number of numbers in the array squared- obviously not what I want. Thanks for any help. Ok, here is my terrible code so far. Trying to pass it to a method as well.
public static void main ( String args[] )
{ double[] nums = {126, 12.939, 795, 320.16, 110, 34.7676, 7773, 67, 567, 323};
System.out.println ("Square root is " +square);
square(nums);
}
public static double square (double [] array) {
double result;
for( double i = 0; i < array.length ; i++ )
result = Math.sqrt(array[i]);
return result;
} }
© Stack Overflow or respective owner