📜  带有示例的 Scala List product() 方法

📅  最后修改于: 2022-05-13 01:54:32.368000             🧑  作者: Mango

带有示例的 Scala List product() 方法

product()方法用于查找所述列表中所有元素的乘积。

示例 #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