</*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package proba;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
/**
*
* @author duugas
*/
public class Proba {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
try {
System.out.println("podaj sciezke do pliku");
BufferedReader sciezka = new BufferedReader(new InputStreamReader(System.in));
String linia = sciezka.readLine();
FileReader plik = new FileReader(linia);
Wypisywanie(plik);
sciezka.close();
plik.close();
} catch (FileNotFoundException e) {
System.out.println("nie ma pliku");
System.exit(1);
}catch (IOException ex) {
ex.printStackTrace();
}
}
public static void Wypisywanie(FileReader r){
Map<Integer,Integer> liczby = new TreeMap<Integer,Integer>();
Scanner scaner = new Scanner(r);
while (scaner.hasNextInt()) {
int liczba = scaner.nextInt();
String slowo = scaner.next();
if (liczby.containsKey(liczba)==false)
liczby.put(liczba, 1);
else
liczby.put(liczba, liczby.get(liczba)+1);
}
scaner.close();
for (Map.Entry<Integer, Integer> entry : liczby.entrySet()) {
System.out.println(entry.getValue()+entry.getKey());
}
}
}
/code>
0
0
gdzie robie blad i dlaczego nie chce mi wyswietlac ile jest liczb i jakie w pliku
0
System.out.println(entry.getValue()+entry.getKey());
Wyświetla sumę wartości i klucza, a nie string z nich złożony. Jeśli to nie to, to powiedz jak działa i co wyświetla.