fork(1) download
  1. import java.io.IOException ;
  2. import java.io.FileReader ;
  3. import java.io.BufferedReader ;
  4. import java.lang.StringBuilder ;
  5.  
  6. class Main
  7. {
  8. private static String getText (String filename) throws IOException
  9. {
  10. StringBuilder sb = new StringBuilder () ;
  11. FileReader fr = new FileReader (filename) ;
  12. BufferedReader br = new BufferedReader (fr) ;
  13. while (true)
  14. {
  15. String line = br .readLine () ;
  16. if (line==null) break ;
  17. sb .append (line) .append ('\n') ;
  18. }
  19. br .close () ;
  20. fr .close () ;
  21. }
  22.  
  23. public static void main (String [] args) throws IOException
  24. {
  25. String text = getText ("/dev/tty") ;
  26. int chars = new TextCharsStat () .getStat (text) ;
  27. int words = new TextWordsStat () .getStat (text) ;
  28. int lines = new TextLinesStat () .getStat (text) ;
  29.  
  30. System.out .printf ("文字数: %d%n", chars) ;
  31. System.out .printf ("単語数: %d%n", words) ;
  32. System.out .printf ("行数: %d%n", lines) ;
  33. }
  34. }
  35.  
  36. abstract class TextStat
  37. {abstract int getStat (String text) ;}
  38.  
  39. class TextCharsStat extends TextStat
  40. {
  41. int getStat (String text)
  42. {return text .replaceAll ("\\s+", "") .length () ;}
  43. }
  44.  
  45. class TextWordsStat extends TextStat
  46. {
  47. int getStat (String text)
  48. {return text .split ("\\W+").length ;}
  49. }
  50.  
  51. class TextLinesStat extends TextStat
  52. {
  53. int getStat (String text)
  54. {return text .split ("\n").length ;}
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/IwrRC7/prog.fs(6,1): error FS0010: Unexpected keyword 'class' in implementation file

/home/IwrRC7/prog.fs(16,23): warning FS0046: The identifier 'break' is reserved for future use by F#

/home/IwrRC7/prog.fs(37,3): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (36:10). Try indenting this token further or using standard formatting conventions.

/home/IwrRC7/prog.fs(39,1): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (36:10). Try indenting this token further or using standard formatting conventions.
stdout
Standard output is empty