Advertisement
allerost

pog

Jan 16th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. package ar223ni_assign4;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.util.Scanner;
  6.  
  7. public class FileStatistics {
  8.     public static void main(String[] args) throws FileNotFoundException {
  9.         FileReader fr = new FileReader("C:\\Users\\Greattech\\Downloads\\lovecraft.txt");
  10.         Scanner sc = new Scanner(fr);
  11.         int totalRows = 0;
  12.         int totalRowsWithText = 0;
  13.         int totalEmptyRows = 0;
  14.         int totalRowsWithMarking = 0;
  15.         String temp = "";
  16.         boolean isLetter = false;
  17.  
  18.  
  19.         while(sc.hasNextLine()){
  20.             temp = sc.nextLine();
  21.             totalRows++;
  22.             if (temp.isEmpty()){
  23.                 totalEmptyRows++;
  24.             }
  25.             else if(temp.chars().sum() > 0){
  26.                 totalRowsWithText++;
  27.             }
  28.             else{
  29.                 temp.replaceAll("\\s", "");
  30.                 for (int i = 0; i < temp.length(); i++) {
  31.                     if(Character.isLetter(temp.charAt(i))){
  32.                         isLetter = true;
  33.                     }
  34.                 }
  35.                 if(!isLetter){
  36.                     totalRowsWithMarking++;
  37.                     isLetter = false;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         System.out.println("Total lines are: " + totalRows);
  43.         System.out.println("total empty lines are: " + totalEmptyRows);
  44.         System.out.println("Lines with text: " + (totalRowsWithText - totalRowsWithMarking));
  45.         System.out.println("Lines with page number: " + totalRowsWithMarking);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement