radko93

Untitled

Jan 20th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class liczenie {
  4.  
  5.     public void policz() {
  6.         try {
  7.             BufferedReader br = new BufferedReader(new FileReader(
  8.                     "/Users/radek/Desktop/elo.txt"));
  9.             int ileWierszy = 0;
  10.             int ileZnakow = 0;
  11.             int ileSlow = 0;
  12.             int ileCzarnych = 0;
  13.             String linia;
  14.  
  15.             while ((linia = br.readLine()) != null) {
  16.                
  17.                 ileWierszy++;
  18.                 ileZnakow+=linia.length();
  19.                 String tab[] = linia.split("\\s");
  20.                 int n=0;
  21.                  while( n<tab.length)
  22.                  {
  23.                      ileCzarnych+=tab[n].length();
  24.                      if(tab[n].length()!=0)
  25.                      ileSlow++;
  26.                      n++;
  27.                  }
  28.  
  29.                 }
  30.  
  31.            
  32.              System.out.println("Ilosc wierszy: "+ileWierszy);
  33.                System.out.println("Ilosc znakow: "+ileZnakow);
  34.                System.out.println("Ilosc czarnych znakow: "+ileCzarnych);
  35.        
  36.                System.out.println("Ilosc wyrazow: "+ileSlow);
  37.              
  38.                System.out.printf("%15d%15d%15d",ileWierszy,ileZnakow,ileCzarnych);
  39.                
  40.             br.close();
  41.         } catch (IOException e) {
  42.             System.out.println(e);
  43.         }
  44.     }
  45.  
  46.     public static void main(String[] args) {
  47. liczenie test= new liczenie();
  48. test.policz();
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment