-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumericData.java
More file actions
28 lines (22 loc) · 811 Bytes
/
NumericData.java
File metadata and controls
28 lines (22 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
Author: Rajin Santos Gajadhar
Student ID: 239479650
Final Exam: Question 12
Any and all work in this file is my own.
*/
import java.util.List;
public class NumericData {
public static double multiplyListElements(List<? extends Number> numbers) {
double product = 1.0;
for (Number number : numbers) {
product *= number.doubleValue();
}
return Math.round(product * 10.0) / 10.0; //one decimal place
}
public static void main(String[] args) {
List<Integer> integerList = List.of(1, 2, 3);
System.out.println("Product of Integer List: " + multiplyListElements(integerList));
List<Double> doubleList = List.of(1.1, 2.0, 3.0);
System.out.println("Product of Double List: " + multiplyListElements(doubleList));
}
}