import java.io.DataInputStream;
class statis
{
public static void main(String[]args) throws Exception
{
DataInputStream dis=new DataInputStream(System.in);
int k;
float n;
double m[]=new double[1000];
float f[]=new float[1000];
float fk[]=new float[1000];
float fr[]=new float[1000];
float data[]=new float[1000];
double interval[]=new double[1000];
double jumlah;//[]=new double[1000];
double hasil;//[]=new double[1000];
int j, q;
String pil="y";
while(pil.equals("y"))
{
System.out.print("masukkan jumlah data=");
n=Float.parseFloat(dis.readLine());
System.out.print("masukkan banyak interval=");
k=Integer.parseInt(dis.readLine());
//input data
for(j=1;j<=n;j++)
{
System.out.print("masukkan data ke "+j+"= ");
data[j]=Float.parseFloat(dis.readLine());
}
//cari max
float max=data[1];
for(j=2;j<=n;j++)
{
if(data[j]>max)
max=data[j];
}
float min=data[1];
for(j=2;j<=n;j++)
{
if(data[j]
min=data[j];
}
//menghitung r
float R=max-min;
System.out.println("Range= "+R);
//menghitung i
double i=Math.ceil(R/k);
System.out.println("i= "+i);
//mencari nilai interval[q]
for(q=1;q<=k+1;q++)
interval[q]=min+(q-1)*i;
//mencari nilai m[q]
for(q=1;q<=n;q++)
{
m[q]=interval[q]+0.5*i;
f[q]=0;
}
//mencari nilai f[q];
for(j=1;j<=n;j++)
{
for(q=1;q<=k;q++)
{
if(data[j]>=interval[q]&&data[j]
f[q]=f[q]+1;
}
}
//mencari nilai fr[q]
for(q=1;q<=k;q++)
fr[q]=f[q]/n;
//mencari nilai fk[q]
fk[1]=f[1];
for(q=2;q<=k;q++)
fk[q]=fk[q-1]+f[q];
//menampilkan interval[q]
for(q=1;q<=k+1;q++)
{
System.out.println("interval ke "+q+" = "+interval[q]);
}
//menampilkan m[q]
for(q=1;q<=k;q++)
{
System.out.println("m ke "+q+" = "+m[q]);
}
//menampilkan f[q]
for(q=1;q<=k;q++)
{
System.out.println("f ke "+q+" = "+f[q]);
}
//menampilkan fr[q]
for(q=1;q<=k;q++)
{
System.out.println("fr ke "+q+" = "+fr[q]);
}
//menampilkan fk[q]
for(q=1;q<=k;q++)
{
System.out.println("fk ke "+q+" = "+fk[q]);
}
//mencari rata-rata
jumlah=0;
for(q=1;q<=k;q++)
{
jumlah=jumlah+m[q]*f[q];
}
hasil=jumlah/fk[k];
System.out.println("rata-rata = "+hasil);
System.out.print("anda ingin mengulang y/t=");
pil=dis.readLine();
System.out.println("===========================");
}
}
}
Hasil Eksekusi
Demikian Sekian dan trimakasih...Bila ada pertanyaan Monggo sedoyo comment...Tapi ingat...blajar memahami lebih baik daripada hanya mengcopy-paste saja...So...Pahamilah......
Tidak ada komentar:
Posting Komentar