How to print vector in Scala

2 Answers

0 votes
object O {
    def main(args: Array[String]): Unit = {
        val vec = Vector(5, 9, 2, 8, 1, 3)  

        print(vec)
        
        println()
        
        vec.foreach(println(_))
    }
}
  
   
   
   
/*
run:
   
Vector(5, 9, 2, 8, 1, 3)
5
9
2
8
1
3
   
*/

 



answered Sep 7, 2020 by avibootz
0 votes
object O {
    def main(args: Array[String]): Unit = {
        val vec = Vector(5, 9, 2, 8, 1)  
 
        for(n<-vec) {  
            println(n)  
        }  
    }
}
   
    
    
    
/*
run:
    
5
9
2
8
1
    
*/

 



answered Sep 7, 2020 by avibootz

Related questions

2 answers 201 views
1 answer 181 views
1 answer 217 views
217 views asked Sep 9, 2020 by avibootz
1 answer 464 views
464 views asked Sep 9, 2020 by avibootz
1 answer 201 views
1 answer 195 views
195 views asked Sep 9, 2020 by avibootz
...