Averages/Root mean square: Difference between revisions
Content added Content deleted
(Added ZX81 BASIC) |
(→{{header|Java}}: consistent formatting, cleanup) |
||
Line 785: | Line 785: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
<lang java>public class |
<lang java>public class RootMeanSquare { |
||
public static double rms(double[] nums){ |
|||
public static double rootMeanSquare(double... nums) { |
|||
double sum = 0.0; |
|||
for (double num : nums) |
|||
sum += num * num; |
|||
return Math.sqrt( |
return Math.sqrt(sum / nums.length); |
||
} |
} |
||
public static |
public static void main(String[] args) { |
||
double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; |
double[] nums = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; |
||
System.out.println("The RMS of the numbers from 1 to 10 is " + |
System.out.println("The RMS of the numbers from 1 to 10 is " + rootMeanSquare(nums)); |
||
} |
} |
||
}</lang> |
}</lang> |