This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Snippet: Sum Arguments

object Main {
  def main(args: Array[String]) {
    try {
      val elems = args map Integer.parseInt
      println("The sum of my arguments is: " + elems.foldRight(0) (_ + _))
    } catch {
      case e: NumberFormatException => 
        println("Usage: scala Main <n1> <n2> ... ")
    }
  }
}

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland