Create a Java program using a method with varargs to calculate the product of doubles
import java.util.Arrays; public class DoubleProductCalculator { static double calculateProduct(double... numbers) { System.out.println("Given Numbers : " + Arrays.toString(numbers)); if (numbers.length == 0) { throw new IllegalArgumentException("No numbers provided"); } double product = 1; for (double num : numbers) { product *= num; } return product; } public static void main(String[] args) { double product = calculateProduct(2.5, 1.5, 3.0); System.out.println("Product : " + product); } }
Given Numbers : [2.5, 1.5, 3.0] Product : 11.25
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions