lr12 -> e2-6
This commit is contained in:
20
lr12/e6.java
Normal file
20
lr12/e6.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package lr12;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class e6 {
|
||||
public static long sum(int[] arr) {
|
||||
if (arr == null || arr.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Arrays.stream(arr)
|
||||
.parallel()
|
||||
.sum();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 128, 512 };
|
||||
System.out.println("Sum = " + sum(array));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user