Problema Programacion Java
Hola a todos.
Ante todo daros las gracias por la ayuda que me podais proporcionar.
Os comento mi problema:
Tengo que hacer una aplicacion en java que sea capaz de leer un archivo .txt con numeros separados por ";" tal que asi:
565;
485;
7846;
454;
Y de esos numeros saque la media y la desviacion estandar.
Ya he creado una aplicacion, pero esta me reporta 2 fallos al intentar compilarla, y ahi es donde necesito su ayuda.
Les adjunto mi código:
Cita:
import java.io.*;
import java.util.ArrayList;
class Estad1
{
public static void main(String arg[ ]) throws IOException
{
ArrayList<Double> lista = new ArrayList<Double>();
try {
FileReader file = new
FileReader("read.txt");
BufferedReader buff = new
BufferedReader(file);
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null) eof = true;
else{
line = line.split(";")[0];
lista.add(Double.parseDouble(line));
}
}
buff.close();
} catch (IOException e) {
System.out.println("Error -- " +e.toString());
}
Object numbers[] = lista.toArray();
System.out.println("\n Resultados \n");
double aux_media = media(numbers);
System.out.println(" media : " + aux_media);
double aux_var = varianza(numbers,aux_media);
System.out.println(" varianza : " + aux_var);
System.out.println(" desv. estandar : " + Math.sqrt(aux_var));
}
public static double media(int arr[ ])
{
double sum = 0.0;
for(int i = 0; i < arr.length ; i++)
{
sum += arr[i];
}
return sum / arr.length;
}
public static double varianza(int arr[ ], double media)
{
double sum = 0.0;
for(int i = 0; i < arr.length ; i++)
{
sum += Math.pow(arr[i] - media, 2);
}
return sum / (arr.length - 1);
}
}
Y el error que me reporta al intentar compilarlo es:
Cita:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method media(int[]) in the type Estad1 is not applicable for the arguments (Object[])
The method varianza(int[], double) in the type Estad1 is not applicable for the arguments (Object[], double)
at Estad1.main(Estad1.java:33)
Espero que puedan ayudarme. Muchas gracias a todos.