Scala Queue product() method with example
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 q 1 = Queue( 1 , 2 , 3 , 4 ) // Print the queue println(q 1 ) // Applying product method val result = q 1 .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 q 1 = Queue( 5 , 2 , 3 , 7 ) // Print the queue println(q 1 ) // Applying product method val result = q 1 .product // Display output print( "5 * 2 * 3 * 7 = " + result) } } |
Output:
Queue(5, 2, 3, 7) 5 * 2 * 3 * 7 = 210