How to sum the elements of array in Scala

1 Answer

0 votes
object O {
    def main(args: Array[String]): Unit = {
        var arr = Array(5, 7, 2.34, 8, 9.648)

        var total = 0.0;
        for (i <- 0 to (arr.length - 1)) {
           total += arr(i);
        }
        
        println(total);
    }
}




/*
run:

31.988

*/

 



answered Sep 6, 2020 by avibootz
...