Advertisement
duc-phan

Untitled

Dec 4th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. public class wc {
  2.     public static void main(String[] args) {
  3.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  4.         String line;
  5.         int lineCount = 0;
  6.         int charCount = 0;
  7.         int wordCount = 0;
  8.         try {
  9.             while ((line = in.readLine()) != null) {
  10.                 lineCount++;
  11.                 charCount += line.length();
  12.                 String words[] = line.split("\\W");
  13.                 wordCount += words.length;
  14.             } //while
  15.             System.out.println("wordCount = " + wordCount);
  16.             System.out.println("lineCount = " + lineCount);
  17.             System.out.println("charCount = " + charCount);
  18.         } // try
  19.         catch (IOException e) {
  20.             System.err.println("Error:" + e.getMessage());
  21.         } //catch
  22.     } //main
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement