How to create a list with the tabulate with values from a function in Scala

1 Answer

0 votes
object O {
    def main(args: Array[String]): Unit = {
        val lst = List.tabulate(6)(x => x * x)
         
        print(lst)
         
        println()
         
        lst.foreach(println(_))
    }
}
  
   
   
   
/*
run:
   
List(0, 1, 4, 9, 16, 25)
0
1
4
9
16
25
   
*/

 



answered Sep 7, 2020 by avibootz
...