fork download
  1. import scala.util.{Try, Success, Failure}
  2.  
  3. def divide: Try[Int] = {
  4. val dividend = Try(Console.readLine("Enter an Int that you'd like to divide:\n").toInt)
  5. val divisor = Try(Console.readLine("Enter an Int that you'd like to divide by:\n").toInt)
  6. val problem = dividend.flatMap(x => divisor.map(y => x/y))
  7. problem match {
  8. case Success(v) =>
  9. println("Result of " + dividend.get + "/"+ divisor.get +" is: " + v)
  10. Success(v)
  11. case Failure(e) =>
  12. println("You must've divided by zero or entered something that's not an Int. Try again!")
  13. println("Info from the exception: " + e.getMessage)
  14. divide
  15. }
  16. }
  17.  
  18. divide
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/opt/scala/bin/scalac: line 50: /dev/null: Permission denied
Main.scala:3: error: expected class or object definition
def divide: Try[Int] = {
^
Main.scala:18: error: expected class or object definition
divide
^
two errors found
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty