You are viewing a single comment's thread. Return to all comments →
public static void plusMinus(List<Integer> arr) { int quantityPositive = 0; int quantityNegative = 0; int quantityZero = 0; BigDecimal resultPositive = BigDecimal.valueOf(0); BigDecimal resultNegative = BigDecimal.valueOf(0); BigDecimal resultZero = BigDecimal.valueOf(0); for(int i = 0; i < arr.size(); i++ ){ if(arr.get(i) > 0){ quantityPositive++; resultPositive = BigDecimal.valueOf(quantityPositive).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP); }else if(arr.get(i) < 0){ quantityNegative++; resultNegative = BigDecimal.valueOf(quantityNegative).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP); }else{ quantityZero++; resultZero = BigDecimal.valueOf(quantityZero).divide(BigDecimal.valueOf(arr.size()), 6, RoundingMode.HALF_UP); } } System.out.println(resultPositive); System.out.println(resultNegative); System.out.println(resultZero); }
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →