Open In App

Scala Queue product() method with example

Last Updated : 29 Oct, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The product() method is utilized to return the product of all the elements of the queue.

Method Definition: def product: A

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

Example #1:




// Scala program of product() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue(1, 2, 3, 4
          
        // Print the queue
        println(q1)
          
        // Applying product method 
        val result = q1.product
          
        // Display output
        print("Product of all the elements of the queue: " + result)
          
    


Output:

Queue(1, 2, 3, 4)
Product of all the elements of the queue: 24

Example #2:




// Scala program of product() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating a queue 
        val q1 = Queue(5, 2, 3, 7
          
        // Print the queue
        println(q1)
          
        // Applying product method 
        val result = q1.product
          
        // Display output
        print("5 * 2 * 3 * 7 = " + result)
          
    


Output:

Queue(5, 2, 3, 7)
5 * 2 * 3 * 7 = 210


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads