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.
- Prepare
- Algorithms
- Warmup
- Plus Minus
- Discussions
Plus Minus
Plus Minus
Sort by
recency
|
3245 Discussions
|
Please Login in order to post a comment
Rust
Great explanation of how to calculate the positive, negative, and zero ratios in an array. I like how clearly the logic was presented. It reminds me of how precision and ratio handling are important in simulation games like Car Parking Multiplayer too
Could not shorten this further
simple java code from scratch
public static void plusMinus(List arr) { // Write your code here int plus=0,minus=0,zero=0,total=0; for(int x:arr) { if(x<0) minus++; else if(x==0) zero++; else if(x>0) plus++; total++;
} double positive=(double)plus/total, negative=(double)minus/total, Zero=(double)zero/total;
System.out.println(String.format("%.6f",positive)); System.out.println(String.format("%.6f",negative)); System.out.println(String.format("%.6f",Zero)); }