1 de diciembre de 2009

PROGRAMAS EN JAVA

MEDIA PARA UNA SERIE DE DATOS
// The "Mediadis" class.
public class Mediadis
{
public static void main (String [] args)
{
int y, i, j = 0;
float M = 0;
int x [] = new int [100];
int n [] = new int [100];
System.out.print ("introducir el numero de clases:");
y = Leer.datoInt ();
System.out.print ("introducir lo x(i):");

for (i = 1 ; i <= y ; i++)
{


x [i] = Leer.datoInt ();
} System.out.print ("introducir los n(i):");

for (i = 1 ; i <= y ; i++)
{
n [i] = Leer.datoInt ();
}
for (i = 1 ; i <= y ; i++)
{
j = j + n [i];
}
for (i = 1 ; i <= y ; i++)
{
M = M + x [i] * n [i];
}



M = M / j;
System.out.print ("La media aritmetica es:M(x)=");
System.out.print (M);

}
}








MEDIA PARA UNA DISTRIBUCION DE FRECUNCIA

public class Media
{
public static void main (String[] args)
{
int n,i;
float M=0;
int x[]= new int [30];

System.out.print("introducir el numero de datos:n");
n=Leer.datoInt();
for(i=1;i<=n;i++)

{x[i]=Leer.datoInt();
}
for(i=1;i<=n;i++)
{ M=M+x[i];
}
M=M/n;
System.out.print("La media aritmetica es:M(x)=");
System.out.print(M);

}
}


VECTOR EN FORMA ACENDENTE

// The "Vectoacenndente" class.
public class Vectoacenndente
{
public static void main (String [] args)
{
int y, i, aux, j = 0;

int A [] = new int [100];

System.out.print ("introducir la cantidad de dsatos del vector:");
y = Leer.datoInt ();
System.out.print ("LLENAR:");

for (i = 1 ; i <= y ; i++)
{


A [i] = Leer.datoInt ();
}

for (i = 1 ; i <= y ; i++)
{


for (j = i+1 ; j <= y ; j++)

{
if (A [i] >= A [j])

{ aux = A [i];
A [i] = A [j];
A [j] = aux ;
} }



}
for (i = 1 ; i <= y ; i++)
{


System.out.println( +A [i]);
}

}
}

No hay comentarios:

Publicar un comentario