Scala Iterator product() 方法与示例
product()方法属于抽象迭代器类的具体值成员。它用于乘以所述集合的所有元素。
Method Definition: val result = iter.product
Return Type: It returns the result obtained by multiplying all the elements of the stated iterator.
示例 #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