【发布时间】:2016-04-28 14:57:55
【问题描述】:
如何使用 Java 8 的流方法拆分奇数和偶数并在集合中求和?
public class SplitAndSumOddEven {
public static void main(String[] args) {
// Read the input
try (Scanner scanner = new Scanner(System.in)) {
// Read the number of inputs needs to read.
int length = scanner.nextInt();
// Fillup the list of inputs
List<Integer> inputList = new ArrayList<>();
for (int i = 0; i < length; i++) {
inputList.add(scanner.nextInt());
}
// TODO:: operate on inputs and produce output as output map
Map<Boolean, Integer> oddAndEvenSums = inputList.stream(); // Here I want to split odd & even from that array and sum of both
// Do not modify below code. Print output from list
System.out.println(oddAndEvenSums);
}
}
}
【问题讨论】:
-
请提供一些代码来展示你到目前为止所做的事情。你有什么尝试。你在哪里搞砸了
-
请立即查看更新的问题! @MarquisBlount
标签: java collections lambda java-8 java-stream