Skip to content

Commit

Permalink
add Scala port of C# version
Browse files Browse the repository at this point in the history
Signed-off-by: George <[email protected]>
  • Loading branch information
George committed Mar 28, 2015
1 parent 46100c6 commit 9d9665a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion check_digits1/check_digits1.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import edu.luc.cs.ui._

object check_digits1 {
def main(args: Array[String]) {
// Put code here
val s = promptLine("Enter a line: ")
if (isDigits(s))
println(s"All characters in $s are digits.")
else
println(s"Some characters in $s are not digits.")
}

def isDigits(s : String) : Boolean = {
var allDigitsSoFar = true
var i = 0
while (i < s.length && allDigitsSoFar) {
if (s(i) < '0' || s(i) > '9') {
allDigitsSoFar = false
}
i += 1
}
allDigitsSoFar
}
}

0 comments on commit 9d9665a

Please sign in to comment.