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
|
278 Discussions
|
Please Login in order to post a comment
Scala
!/bin/python3
import math import os import random import re import sys
#
Complete the 'plusMinus' function below.
#
The function accepts INTEGER_ARRAY arr as parameter.
#
def plusMinus(arr): pos_num = 0 neg_num = 0 zero_num = 0
iterate over array
Calculate totals
Print totals
if name == 'main': n = int(input().strip())
This is the Java code
public static void plusMinus(List arr) { // Write your code here int len=arr.size(); float posCount=0; float negCount=0; float zeroCount=0; for(int i = 0; i < len ; i++) { int elements = arr.get(i); if(elements>0){ posCount++; } else if(elements<0){ negCount++; } else{ zeroCount++; } } System.out.printf("%.6f%n",posCount/len); System.out.printf("%.6f%n",negCount/len); System.out.printf("%.6f%n",zeroCount/len);
}
foreach(int number in arr) { if (number>0) {
positives+=1; } else if (number<0) { negatives+=1; } else { zeros+=1; }
} System.Console.WriteLine("{(negatives/arr.Count):F6}"); System.Console.WriteLine($"{(zeros/arr.Count):F6}");