fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int product(int...numbers)
  11. {
  12.  
  13. int product = 1;
  14.  
  15. //multiplies the integers
  16. for (int number:numbers)
  17. {
  18. product *= number;
  19. }
  20. return product;
  21. }
  22.  
  23. public static void main(String[] args)
  24. {
  25.  
  26. int a = 1;
  27. int b = 2;
  28. int c = 3;
  29. int d = 4;
  30. int e = 5;
  31.  
  32. //displays the values
  33. System.out.printf("a = %d, b = %d, c = %d, d = %d, e = %d\n",a, b, c, d, e);
  34.  
  35. //calls the product of the values with a different number of arguments in each call
  36.  
  37. System.out.printf("The product of a and b is: %d\n",product(a, b));
  38.  
  39. System.out.printf("The product of a, b and c is: %d\n",product(a, b, c));
  40.  
  41. System.out.printf("The product of a, b, c and d is: %d\n", product(a, b, c, d));
  42.  
  43. System.out.printf("The product of a, b, c, d and e is: %d\n", product(a, b, c, d, e));
  44. }
  45. }
  46.  
Success #stdin #stdout 0.08s 34260KB
stdin
Standard input is empty
stdout
a = 1, b = 2, c = 3, d = 4, e = 5
The product of a and b is: 2
The product of a, b and c is: 6
The product of a, b, c and d is: 24
The product of a, b, c, d and e is: 120