Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class liczenie {
- public void policz() {
- try {
- BufferedReader br = new BufferedReader(new FileReader(
- "/Users/radek/Desktop/elo.txt"));
- int ileWierszy = 0;
- int ileZnakow = 0;
- int ileSlow = 0;
- int ileCzarnych = 0;
- String linia;
- while ((linia = br.readLine()) != null) {
- ileWierszy++;
- ileZnakow+=linia.length();
- String tab[] = linia.split("\\s");
- int n=0;
- while( n<tab.length)
- {
- ileCzarnych+=tab[n].length();
- if(tab[n].length()!=0)
- ileSlow++;
- n++;
- }
- }
- System.out.println("Ilosc wierszy: "+ileWierszy);
- System.out.println("Ilosc znakow: "+ileZnakow);
- System.out.println("Ilosc czarnych znakow: "+ileCzarnych);
- System.out.println("Ilosc wyrazow: "+ileSlow);
- System.out.printf("%15d%15d%15d",ileWierszy,ileZnakow,ileCzarnych);
- br.close();
- } catch (IOException e) {
- System.out.println(e);
- }
- }
- public static void main(String[] args) {
- liczenie test= new liczenie();
- test.policz();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment