In JAVA
Write an application that calculates the product of a series of integers that are passed to method product using a variable-length argument list, Test your method with several calls, each with a different number of arguments.
// This class ProductOfIntegers finds the product of series of
integers that
// are passed to a method product using a variable-length argument
list.
public class ProductOfIntegers
{
// A method that takes variable number of integer arguments.
// Variable length arguments are specified by three periods (...)
after datatype
static void product(int... num)
{
System.out.println();
//num.length will give the total number of integers per call
System.out.println("Number of integers: " +
num.length);
if ( num.length > 0) // if atleast one argument
is given in the function call
{
int prod = 1; // intitialize prod with multiplicative
identity
// using for each loop to find the product of all integers
for (int n: num)
prod = prod * n;
// print the result in formatted way
System.out.print("Product of integers ( * ");
for (int n: num)
System.out.print(n + " * " );
System.out.print(") = " + prod);
System.out.println();
}
else /* if no arguments were given */
{
System.out.println("Multiplication is not possible");
}
}
// Driver code
public static void main(String args[])
{
// Calling the product method with different number of
parameters
product(6); // one parameter
product(9 , 8); // two parameters
product(10, 2, 33, 4); // four parameters
product(1, 2, 3, 4, 5, 6); // six parameters
product(); // no parameter
}
}
Sample output:

In JAVA Write an application that calculates the product of a series of integers that are...