📜  Scala Iterator product() 方法与示例

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

Scala Iterator product() 方法与示例

product()方法属于抽象迭代器类的具体值成员。它用于乘以所述集合的所有元素。

示例 #1:

// Scala program of product()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(1, 2, 3, 4, 5, 6)
          
        // Applying product method 
        val result = iter.product
          
        // Displays output
        println(result)
      
    }
}
输出:
720

示例 #2:

// Scala program of product()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating a Iterator 
        val iter = Iterator(0, 1)
          
        // Applying product method 
        val result = iter.product
          
        // Displays output
        println(result)
      
    }
}
输出:
0