Loading...

Hacker Rank – Functional Programming in Scala

Print “Hello World” on a new line ‘n’ times.

Challenge 2:

object Solution {
 def main(args: Array[String]) {
 val sc = new java.util.Scanner (System.in);
 var n = sc.nextInt();
 // Print "Hello World" on a new line 'n' times.
 f(5);
 }
}

def f(n: Int) = (1 to n) foreach(x => println("Hello World"))

Leave a Reply

Your email address will not be published. Required fields are marked *