private long wc(String text){
  long wc=0;
  String[] lines=text.split("\n");
  for (  String line : lines) {
    wc+=line.split("\\s+").length;
  }
  return wc;
}

private long wc ( String text ) { long wc = 0 ; String [ ] lines = text . split ( "\n" ) ; for ( String line : lines ) { wc += line . split ( "\\s+" ) . length ; } return wc ; }
count the words of a text file .
