Scala Stack product() method with example
Last Updated :
03 Nov, 2019
In Scala Stack class
, the product() method is utilized to return the product of all the elements of the stack.
Method Definition: def product: A
Return Type: It returns the product of all the elements of the stack.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 1 , 2 , 3 , 4 )
println(s 1 )
val result = s 1 .product
print( "Product of all the elements of the stack: " + result)
}
}
|
Output:
Stack(1, 2, 3, 4)
Product of all the elements of the stack: 24
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 5 , 2 , 3 , 7 )
println(s 1 )
val result = s 1 .product
print( "Product of all the elements of the stack: " + result)
}
}
|
Output:
Stack(5, 2, 3, 7)
Product of all the elements of the stack: 210
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...