1 / 5
Jun 2010

object Main{
    def main(args: Array[String]){
        var x = 0
        var f = true
        while(f){
            x = readInt()
            if(x != 42)
                println(x)
            else
                f = false
        }
    }
}

The number of problems that can be solved with Scala is quite limited due to long time needed to start it up. I think the time limit should be at least 2 or 3s.
2015-01-25: Modified slightly as the previously shown code did not compile anymore.

  • created

    Jun '10
  • last reply

    Jul '11
  • 4

    replies

  • 1.9k

    views

  • 4

    users

1 month later
1 month later

Try this:

import scala.io._
object Main {
  def main(args: Array[String]) {
    Source.fromInputStream(System.in).getLines.takeWhile(!_.equals("42")).foreach(n => print(n)) 
  }
}
9 months later