Permalink
Browse files

ch08_methods.scala: method and private method

  • Loading branch information...
1 parent a537be9 commit eab41ac13009251bab98280fb6017775c02b6e07 Wiggert committed Apr 17, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 ch08_methods.scala
View
@@ -0,0 +1,22 @@
+import scala.io.Source
+
+object LongLines {
+ def processFile(filename: String, width: Int) {
+ val source = Source.fromFile(filename)
+ for (line <- source.getLines())
+ processLine(filename, width, line)
+ }
+
+ private def processLine(filename: String, width: Int, line: String) {
+ if (line.length > width)
+ println(filename +": "+ line.trim)
+ }
+}
+
+object FindLongLines {
+ def main(args: Array[String]) {
+ val width = args(0).toInt
+ for (arg <- args.drop(1))
+ LongLines.processFile(arg, width)
+ }
+}

0 comments on commit eab41ac

Please sign in to comment.