RMS of an array
Problem Statement
Given an array A of size N. You need to find the root mean square (RMS) of the array i. e you first need to square all values of array and take its mean. Then you need to return the square root of mean. Print the answer with precision upto 6 decimal places.
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n= sc.nextInt();
int a[]=new int[n];
double rms=0;
double sum=0;
for (int i=0;i<n;i++)
{
a[i]=sc.nextInt();
sum=sum+a[i]*a[i];
}
double ans =sum/n;
rms=rms+Math.sqrt(ans);
System.out.format("%.6f", rms);
}
}