public class methods { public static void main(String[] args) { //Scanner scanner = new Scanner(System.in); double[] array = {2.3, 4.5, 6.7, 3.9}; double product = product(array); System.out.println("The product of all double number in the array are = " + product); double sum = sum(array); System.out.println("The sum of all number in the array are = " + sum); } public static double product(double[] array) { double product = 1.0; for(int i=0; i<array.length; i++) { product = product * array[i]; } return product; } public static double sum(double[] array) { double sum =0; for(int i=0; i<array.length; i++) { sum = sum + array[i]; } return sum; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter