Buatlah Program untuk Menghitung Standar Deviasi!
P E N Y E L E S A I A N :
package Soal9;
import java.lang.Math;
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("Program Menghitung Standar Deviasi");
System.out.println("____________________________________");
System.out.print("Jumlah bilangan = ");
Scanner input = new Scanner(System.in);
int banyakdata = input.nextInt();
System.out.println("\n");
double[] arraybilangan = new double[banyakdata];
for(int i = 0;i<banyakdata;i++){
System.out.print("Masukkan Data Ke- " + (i+=0)+"\t : ");
arraybilangan[i] = input.nextDouble();
}
System.out.println("Jumlah Bilangan : "+TotalJumlah(arraybilangan));
System.out.println("Rata - rata : "+ratarata(arraybilangan));
System.out.println("Standar Deviasi : "+hasil(arraybilangan));
}
public static int TotalJumlah(double [] data){
int result = 0;
for (int i = 0 ; i < data.length ; i++){
result += data[i];
}
return result;
}
public static double ratarata(double [] data){
return
TotalJumlah(data)/data.length;
}
public static double hasil (double [] data){
double ratarata = ratarata(data);
double akarjum = 0;
for (int i=0;i<data.length;i++){
akarjum += Math.pow(data[i] - ratarata,2);
}
return
Math.sqrt(akarjum)/(data.length);
}
}
H A S I L :
Friday, 12 February 2016
Home »
» Menghitung Standar Deviasi || Pemograman Java
0 komentar:
Post a Comment