Created
July 28, 2017 19:21
-
-
Save LuisHCK/89886e7f1134a93264d0cad8bd0aa800 to your computer and use it in GitHub Desktop.
Crear una tabla de frecuencias mediante a partir de un string. Uso => 1,2,3,4,5...n
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import java.util.List; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class EntradaDatos { | |
public static List<Integer> Datos = new ArrayList<Integer>(); | |
public static void main(String[] args) throws IOException { | |
//Lee un dato de la consola | |
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in)); | |
System.out.println("Introduzca los valores seguido de ENTER"); | |
//Convierte el texto en un arreglo | |
String[] datos = entrada.readLine().split(","); | |
//Pasa los datos Una lista para un mejor manejo | |
for (int i = 0; i < datos.length; i++) { | |
Datos.add(Integer.parseInt(datos[i])); | |
} | |
System.out.println("Los datos son: " + Datos.toString()); | |
//System.out.println("El limite inferior es: " + Collections.max(Datos)); | |
//Calcular el rango | |
Integer rango = Collections.max(Datos) - Collections.min(Datos); | |
System.out.println("Rango: " + rango); | |
System.out.println("--------------------------"); | |
//Calcular numero de intervalos | |
Integer numerodatos = Datos.size(); | |
Integer intervalos = (int) (Math.round((1+3.32)*Math.log10(numerodatos)-0.5)); | |
System.out.println("Numero de Intervalos: " + intervalos); | |
System.out.println("--------------------------"); | |
//Calcular Amplitud de la clase | |
Integer amplitud = (int) (Math.round((double)rango/(double)intervalos)); | |
System.out.println("Amplitud " + amplitud); | |
System.out.println("--------------------------"); | |
//Nuevo rango | |
rango = intervalos*amplitud; | |
System.out.println("Nuevo rango :" + rango); | |
System.out.println("\n=======TABLA DE FRECUENCIAS======"); | |
System.out.format("+--------+----+----+----+----+----+----+%n"); | |
System.out.format("| Clases | f | Ci | fi | Fi | ni | Fa |%n"); | |
System.out.format("+--------+----+----+----+----+----+----+%n"); | |
Integer clase_anterior = 0; | |
Integer frAbs = 0; | |
Integer frAcm = 0; | |
Double frRel = 0.0; | |
Double frRelAc = 0.0; | |
for (int i=0; clase_anterior < Collections.max(Datos); i++) { | |
Integer nueva_clase = clase_anterior + (intervalos-1); | |
Double Ci = ((double)(nueva_clase+clase_anterior)/2); | |
frAbs = frecuenciaAbsoluta(clase_anterior, nueva_clase); | |
frAcm += frAbs; | |
frRel = (double)frAbs/Datos.size(); | |
frRelAc = (double) frAcm/Datos.size(); | |
System.out.println("| " + clase_anterior + "," + nueva_clase + " | " + Ci + " | " + frAbs + " | " + frAcm + " | " + frRel+ " | " + frRelAc); | |
clase_anterior = nueva_clase; | |
} | |
System.out.format("+--------+----+----+----+----+----+----+%n"); | |
} | |
/** | |
* Cuenta los numeros que estan dentro de un rango de datos | |
* @param limInf | |
* @param limSup | |
* @return | |
*/ | |
private static int frecuenciaAbsoluta(Integer limInf, Integer limSup) { | |
int count = 0; | |
for (int i = 0; i < Datos.size(); i++) { | |
if (Datos.get(i) >= limInf && Datos.get(i) < limSup) { | |
count++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yo lo corri en IJ y va todo bien @Lexx572