We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Plus Minus
- Discussions
Plus Minus
Plus Minus
Sort by
recency
|
611 Discussions
|
Please Login in order to post a comment
I didn't think through the printing part a lot, I want to come up with an algorithm instead of hardcoding.
JAVA 8 public static void plusMinus(List arr) { // Write your code here double arrSize = arr.size(); double positiveIntSize = arr.stream().filter(number -> number > 0).collect(Collectors.toList()).size(); double negativeIntSize = arr.stream().filter(number -> number < 0).collect(Collectors.toList()).size(); double zeroNumberListSize = arrSize - positiveIntSize - negativeIntSize; System.out.printf("%.6f%n", positiveIntSize/arrSize); System.out.printf("%,6f%n",negativeIntSize/arrSize); System.out.printf("%,6f%n",zeroNumberListSize/arrSize); }
Java Code
}
let num = arr.length;
const positive: number[] = arr.filter(num => num > 0); const negative: number[] = arr.filter(num => num < 0); const zero: number[] = arr.filter(num => num == 0);
}