Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ar223ni_assign4;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Scanner;
- public class FileStatistics {
- public static void main(String[] args) throws FileNotFoundException {
- FileReader fr = new FileReader("C:\\Users\\Greattech\\Downloads\\lovecraft.txt");
- Scanner sc = new Scanner(fr);
- int totalRows = 0;
- int totalRowsWithText = 0;
- int totalEmptyRows = 0;
- int totalRowsWithMarking = 0;
- String temp = "";
- boolean isLetter = false;
- while(sc.hasNextLine()){
- temp = sc.nextLine();
- totalRows++;
- if (temp.isEmpty()){
- totalEmptyRows++;
- }
- else if(temp.chars().sum() > 0){
- totalRowsWithText++;
- }
- else{
- temp.replaceAll("\\s", "");
- for (int i = 0; i < temp.length(); i++) {
- if(Character.isLetter(temp.charAt(i))){
- isLetter = true;
- }
- }
- if(!isLetter){
- totalRowsWithMarking++;
- isLetter = false;
- }
- }
- }
- System.out.println("Total lines are: " + totalRows);
- System.out.println("total empty lines are: " + totalEmptyRows);
- System.out.println("Lines with text: " + (totalRowsWithText - totalRowsWithMarking));
- System.out.println("Lines with page number: " + totalRowsWithMarking);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement