Created
November 15, 2011 00:32
-
-
Save lfborjas/1365695 to your computer and use it in GitHub Desktop.
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
/**Programa que genera un arreglo con tamaño aleatorio de enteros aleatorios | |
e imprime un histograma de frecuencias | |
*/ | |
//clase de java para generar números aleatorios: | |
import java.util.Random; | |
//sirve para representar colecciones tabulares | |
import java.util.HashMap; | |
//contiene distintas utilidades para colecciones | |
import java.util.Collections; | |
//para poder iterar sobre el mapa | |
import java.util.Map.Entry; | |
import java.util.Arrays; | |
public class Histograma{ | |
public static void main (String [] args){ | |
HashMap<Character, Integer> tabla = new HashMap<Character, Integer>(); | |
String input = "this is an example for huffman encoding"; | |
for(char c: input.toCharArray()){ | |
if(!tabla.containsKey(c)) | |
tabla.put(c, new Integer(1)); | |
else | |
tabla.put(c, tabla.get(c)+1); //reemplazar el valor viejo por su sucesor | |
} | |
System.out.printf("Podés ver todos los valores en una colección con este método: %s\n", tabla.values()); | |
for(Entry<Character, Integer> fila: tabla.entrySet()){ | |
System.out.printf("%s: %s\n",fila.getKey(), fila.getValue()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment