1. Plus Minus Problem
  2.  
  3. Given an array of integers, calculate the ratios of its elements that are positive, negative, and zero. Print the decimal value of each fraction on a new line with places after the decimal.
  4.  
  5. Note: This challenge introduces precision problems. The test cases are scaled to six decimal places, though answers with absolute error of up to are acceptable.
  6.  
  7.  
  8.  
  9. public static void plusMinus(List<Integer> arr) {
  10. // Write your code here
  11. double pos=0;
  12. double neg=0;
  13. double zero=0;
  14. double n=arr.size();
  15. for(int i:arr)
  16. {
  17. if(i>0)
  18. pos++;
  19. if(i<0)
  20. neg++;
  21. if(i==0)
  22. zero++;
  23. }
  24. Formatter fm=new Formatter();
  25. fm.format("%.6f", pos/n);
  26. System.out.println(fm);
  27. fm=new Formatter();
  28. fm.format("%.6f", neg/n);
  29. System.out.println(fm);
  30. fm=new Formatter();
  31. fm.format("%.6f", zero/n);
  32. System.out.println(fm);
  33.  
  34.  
  35. }
  36.