Scala Set product() 方法与示例
product()方法用于查找集合中所有元素的乘积。
Method Definition: def product: A
Return Type: It returns the product of all the elements of the set.
示例 #1:
// Scala program of product()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(1, 2, 3)
// Applying product method
val result = s1.product
// Display output
println(result)
}
}
输出:
6
示例 #2:
// Scala program of product()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(1, 2, 3, 4, 5)
// Applying product method
val result = s1.product
// Display output
println(result)
}
}
输出:
120