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.
Could have done the conditionals and assigning arr the scanner.nextInt() numbers all in one for loop:
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscanner=newScanner(System.in);intsize=scanner.nextInt();int[]a=newint[size];doublefractionPositive=0;doublefractionZero=0;doublefractionNegative=0;for(inti=0;i<size;i++){a[i]=scanner.nextInt();if(a[i]>0)fractionPositive+=1;elseif(a[i]==0)fractionZero+=1;elseif(a[i]<0)fractionNegative+=1;}System.out.println(fractionPositive/size);System.out.println(fractionNegative/size);System.out.println(fractionZero/size);}}
Cookie support is required to access HackerRank
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 →
Could have done the conditionals and assigning arr the scanner.nextInt() numbers all in one for loop: