Deseo que un código en JAVA, cuente la cantidad de palabras que son de 1 a 15 caracteres de longitud y luego lo represente en un diagrama horizontal, mediante "*", tantas veces como aparece la palabra.
Mi código es este, no esta terminado y el resultado que da no es correcto, pero no se como resolverlo.
Código PHP:
Ver original/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pruebas;
import java.io.*;
import java.util.*;
/**
*
* @author Joan
*/
public class Pruebas {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ArrayList<Integer> histo = new ArrayList<Integer>();
int i=0;
//int[] histo = new int[i];
int[] hist2 = new int[15];
try {
archivo
= new File("c:\\ficheros\\fichero.txt");//"archivo.txt" es el archivo que va a leer String linea, f1=("c:\\ficheros\\fichero.txt");
FileReader fr = new FileReader (archivo);
BufferedReader br = new BufferedReader(fr);
Scanner sc
= new Scanner
(new File(f1
));
int j,a=0;
estadisticas(sc);
sc.close();
fr.close();
}
catch(IOException a){
}
}
}
static void estadisticas(Scanner s) {
ArrayList<Integer> histo = new ArrayList<Integer>();
int nPalabras = 0, nChars = 0, i = 0, u1=0, c=0;
String p=null;
while (s.hasNext()){
nPalabras++;
nChars+=p.length();
for(i=0;i<16;i++){
if(p.length()==i){
u1++;
}
histo.add(u1);
}
}
System.out
.println
("Numero total de palabras: " + nPalabras
);
Iterator t = histo.iterator();
while(t.hasNext()){
c++;
System.out
.println
("Palabras de "+c
+": "+t
.next()); }
}
}