Scala Queue product() method with example
Last Updated :
29 Oct, 2019
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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 1 , 2 , 3 , 4 )
println(q 1 )
val result = q 1 .product
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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 5 , 2 , 3 , 7 )
println(q 1 )
val result = q 1 .product
print( "5 * 2 * 3 * 7 = " + result)
}
}
|
Output:
Queue(5, 2, 3, 7)
5 * 2 * 3 * 7 = 210
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...