import java.io.IOException ;
import java.io.FileReader ;
import java.io.BufferedReader ;
import java.lang.StringBuilder ;
class Main
{
private static String getText (String filename) throws IOException
{
StringBuilder sb = new StringBuilder () ;
FileReader fr = new FileReader (filename) ;
BufferedReader br = new BufferedReader (fr) ;
while (true)
{
String line = br .readLine () ;
if (line==null) break ;
sb .append (line) .append ('\n') ;
}
br .close () ;
fr .close () ;
}
public static void main (String [] args) throws IOException
{
String text = getText ("/dev/tty") ;
int chars = new TextCharsStat () .getStat (text) ;
int words = new TextWordsStat () .getStat (text) ;
int lines = new TextLinesStat () .getStat (text) ;
System.
out .
printf ("文字数: %d%n", chars
) ; System.
out .
printf ("単語数: %d%n", words
) ; System.
out .
printf ("行数: %d%n", lines
) ; }
}
abstract class TextStat
{abstract int getStat (String text) ;}
class TextCharsStat extends TextStat
{
int getStat (String text)
{return text .replaceAll ("\\s+", "") .length () ;}
}
class TextWordsStat extends TextStat
{
int getStat (String text)
{return text .split ("\\W+").length ;}
}
class TextLinesStat extends TextStat
{
int getStat (String text)
{return text .split ("\n").length ;}
}