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

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

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

product()方法用于返回 TreeSet 的所有元素的乘积。

示例 #1:

// Scala program of product() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating TreeSet
        val t1 = TreeSet(3, 1, 5, 2, 4)  
            
        // Print the TreeSet 
        println(t1) 
          
        // Applying product method  
        val result = t1.product
            
        // Displays output  
        print("Product of all elements of the TreeSet: " + result) 
          
    } 
} 
输出:
TreeSet(1, 2, 3, 4, 5)
Product of all elements of the TreeSet: 120

示例 #2:

// Scala program of product() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
      
        // Creating TreeSet
        val t1 = TreeSet(3, 7, 5, 2)  
            
        // Print the TreeSet 
        println(t1) 
          
        // Applying product method  
        val result = t1.product
            
        // Displays output  
        print("Product of all elements of the TreeSet: " + result) 
          
    } 
} 
输出:
TreeSet(2, 3, 5, 7)
Product of all elements of the TreeSet: 210