Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

String#length

export JAVA_OPTS='-Dfile.encoding=UTF-8'
  • Loading branch information...
commit 2a77eedbd42d8da46b7e3c0fcd8aaf7b344473ae 1 parent f03cfd0
rightgo09 authored
Showing with 14 additions and 0 deletions.
  1. +12 −0 03-05/TextCounter040.scala
  2. +2 −0  03-05/data.txt
12 03-05/TextCounter040.scala
View
@@ -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  03-05/data.txt
View
@@ -0,0 +1,2 @@
+Hello Wolrd
+Scala Programming Sample
Please sign in to comment.
Something went wrong with that request. Please try again.