Skip to content
Related Articles

Related Articles

Scala Set product() method with example
  • Last Updated : 18 Oct, 2019

The product() method is utilized to find the product of all the elements of the set.

Method Definition: def product: A

Return Type: It returns the product of all the elements of the set.

Example #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)
    
Output:
6

Example #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)
    
Output:
120



My Personal Notes arrow_drop_up
Recommended Articles
Page :