我試圖獲得一個數字(9)數字平方根然後打印,但我一直回來只有一個結果 - 數組中的數字平方數 - 顯然不是我想要的。謝謝你的幫助。好的,到目前爲止,這是我可怕的代碼。試圖將它傳遞給一個方法。陣列 - 打印結果的數組的平方根JAVA
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;
}
}
首先發布你的代碼,這將幫助我們幫助你:-) – 2010-05-31 19:35:27
平方根!=方形:你想要哪一個?另外,你是否想對數組的每個元素進行平方並返回一個新數組,或者可能是數組中每個元素的平方和?我認爲你需要更精確的實際需要。 – 2010-05-31 19:50:32