Skip to content

Commit

Permalink
String#length
Browse files Browse the repository at this point in the history
export JAVA_OPTS='-Dfile.encoding=UTF-8'
  • Loading branch information
rightgo09 committed Dec 30, 2012
1 parent f03cfd0 commit 2a77eed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 03-05/TextCounter040.scala
@@ -0,0 +1,12 @@
import scala.io.Source

val filename = args(0)
val src = Source.fromFile(filename) // オブジェクトを取得
var charCount = 0
var lineCount = 0
val lines = src.getLines
for (line <- lines) {
charCount += line.length
lineCount += 1
}
println("文字数 = " + charCount + ", 行数 = " + lineCount)
2 changes: 2 additions & 0 deletions 03-05/data.txt
@@ -0,0 +1,2 @@
Hello Wolrd
Scala Programming Sample

0 comments on commit 2a77eed

Please sign in to comment.