In: Computer Science
Find the Standard Deviation in Java: Use Arrays and Looping. Calculate the Standard Deviation once you have the m numbers in an Array of size m. *Don't use different methods
import java.util.Scanner; public class TestCode { public static void main(String args[]){ int n; Scanner scanner = new Scanner(System.in); System.out.print("How many input numbers: "); n = scanner.nextInt(); double arr[] = new double[n]; System.out.print("Enter "+ n +" numbers: "); for(int i = 0;i<n;i++){ arr[i] = scanner.nextDouble(); } double sum = 0; for(int i = 0;i<n;i++){ sum += arr[i]; } double mean = sum/n; double res = 0; for(int i = 0;i<n;i++){ res += Math.pow(arr[i]-mean,2); } res = (float) Math.sqrt(res/ (n-1)); System.out.println("Standard deviation: "+ res); } }