Skip to content

Commit 0f3e0c1

Browse files
authored
Add files via upload
1 parent 6a9cb6c commit 0f3e0c1

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problemsolving;
2+
3+
import java.util.Arrays;
4+
5+
public class StreamsAverage {
6+
7+
public static void main(String[] args) {
8+
int arr[] = {5, 2, 7, 6, 5, 5, 10, 15, 13, 13, 14, 1, 3, 1, 2};
9+
10+
for (int num : arr) {
11+
System.out.print("The numbers: " + num + ", ");
12+
}
13+
14+
// Using streams to get the average from that array.
15+
double average = Arrays.stream(arr)
16+
.average()
17+
.orElse(0.0);
18+
19+
System.out.println("Average: " + average);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)