Advertisement
Guest User

hw

a guest
Sep 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3.  
  4. public class CountNumLines {
  5.    
  6.    
  7.    
  8.     public static void main(String[] args) throws Exception{
  9.    
  10.         BufferedReader b = new BufferedReader(new FileReader("H:\\workspace\\Unit1\\src\\words.txt"));
  11.        
  12.         String text = null;
  13.         int noOfLines = 1;
  14.         int blankLines = 0;
  15.         int lWithWords = 0;
  16.         int wordsAmend = 0;
  17.         char[] words;
  18.         String[] spaceWords = null;
  19.         while((text = b.readLine()) != null ) {
  20.             noOfLines = noOfLines +1;
  21.            
  22.            
  23.             if(text.isEmpty() || text.endsWith(" ")) {
  24.                 blankLines++;
  25.             }else {
  26.                 words = text.toCharArray();
  27.                 for(int i=0;i<words.length;i++) {
  28.                     if(words[i] == ' ') {
  29.                         wordsAmend++;
  30.                         spaceWords[noOfLines] = text;
  31.                         System.out.println(spaceWords);
  32.                         break;
  33.                     }
  34.                 }
  35.             }
  36.            
  37.         }
  38.        
  39.         System.out.println("Number of lines was " +noOfLines);
  40.         System.out.println("No. of blank lines is " +blankLines);
  41.         System.out.println(wordsAmend);
  42.        
  43.     }
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement