Reply To: Plus Minus

#4454 Reply

Nav Singh
Keymaster
import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        int la = in.nextInt();
        int arr[] = new int[la];
        int negativeCount = 0;
        int zeroCount = 0;
        int positiveCount = 0;
        for(int i=0; i<la;i++){
        arr[i] = in.nextInt();
            int n = arr[i];
            
          if(n < 0){
          negativeCount += 1;  
        }
        else if(n ==0){
          zeroCount += 1;
        }
        else{
         positiveCount += 1;  
        }
        
        }
        double fractionForPositiveNumbers = (double)positiveCount/(double)la;
        double fractionForNegativeNumbers = (double)negativeCount/(double)la;
        double fractionForZero = (double)zeroCount/(double)la;
            
        System.out.println(fractionForPositiveNumbers);
        System.out.println(fractionForNegativeNumbers);
        System.out.println(fractionForZero);
        
    }
}
Official Forum

This is the Official Forum of Navsingh a community that helps you find answers to all of your problems,they can be Java/programming,wordpress,android, android programming, seo related or technology related