Guest User

hackerrank scala i/o stdin stdout

a guest
Oct 19th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.40 KB | None | 0 0
  1. object hackerrank {
  2.   object Solution {
  3.     def main(args: Array[String]) {
  4.       def fact(n: Int): Int = if (n == 1) 1 else n * fact(n - 1)
  5.  
  6.       for (n <- io.Source.stdin.getLines) {
  7.         print(fact(Integer.parseInt(n.toString)) + "\n")
  8.       }
  9.     }
  10.   }
  11.  
  12.   val stdinString = "2\n3\n5"
  13.  
  14.   System.setIn(new java.io.ByteArrayInputStream(stdinString.getBytes("UTF-8")))
  15.   Solution.main(null)
  16. }
Add Comment
Please, Sign In to add comment