// Scala program of sum()// method// Creating objectobject GfG
{// Main methoddef main(args:Array[String]){// Creating a listval m1 = List(1,2,3,4,5,7)// Applying sum methodval result = m1.sum
// Displays output
println(result)}}
Scala
输出。
22
Scala
例子#2。
// Scala program of sum()// method// Creating objectobject GfG
{// Main methoddef main(args:Array[String]){// Creating a listval m1 = List(1,0)// Applying sum methodval result = m1.sum
// Displays output
println(result)}}