Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- public class CountNumLines {
- public static void main(String[] args) throws Exception{
- BufferedReader b = new BufferedReader(new FileReader("H:\\workspace\\Unit1\\src\\words.txt"));
- String text = null;
- int noOfLines = 1;
- int blankLines = 0;
- int lWithWords = 0;
- int wordsAmend = 0;
- char[] words;
- String[] spaceWords = null;
- while((text = b.readLine()) != null ) {
- noOfLines = noOfLines +1;
- if(text.isEmpty() || text.endsWith(" ")) {
- blankLines++;
- }else {
- words = text.toCharArray();
- for(int i=0;i<words.length;i++) {
- if(words[i] == ' ') {
- wordsAmend++;
- spaceWords[noOfLines] = text;
- System.out.println(spaceWords);
- break;
- }
- }
- }
- }
- System.out.println("Number of lines was " +noOfLines);
- System.out.println("No. of blank lines is " +blankLines);
- System.out.println(wordsAmend);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement