Source Code Standar Deviasi, Jumlah, Rata-rata dalam Java:
/**
*
* @author HERMAWANKUSUMA
*/
import java.lang.Math;
import java.util.Scanner;
public class sd {
public static void main (String[] args){
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);
}
}
Tidak ada komentar:
Posting Komentar