Scala List product() 方法及示例
product()方法是用来寻找所述列表中所有元素的乘积的。
方法定义: def product(num: math.Numeric[B]):B
返回类型。它返回所述列表中所有元素的乘积。
例子 #1:
// Scala program of product()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List(1, 2, 3, 4, 5)
          
        // Applying product method
        val result = m1.product
          
        // Displays output
        println(result)
          
    }
}
输出。
120
例如:2#
// Scala program of product()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a list
        val m1 = List(1, 0)
          
        // Applying product method
        val result = m1.product
          
        // Displays output
        println(result)
          
    }
}
输出。
0
极客教程