Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- class Main{
- public static void main(String args[]) throws Exception{
- File file = new File("hello.txt");
- Scanner sc = new Scanner(file);
- int numLines=0, numWords=0, numChars=0;
- String line = "";
- String[] words;
- while (sc.hasNextLine()){
- line = sc.nextLine();
- System.out.println(line);
- numLines += 1;
- numChars += line.length();
- words = line.split("\\s");
- numWords += words.length;
- }
- System.out.println("Characters : " + numChars);
- System.out.println("Words : " + numWords);
- System.out.println("Lines : " + numLines);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement