| 1 | class Result |
| 2 | { |
| 3 | static int findEarliestMontth(int arr[]){ |
| 4 | int month=0; |
| 5 | int change=Integer.MAX_VALUE; |
| 6 | int tsum=0; |
| 7 | int s=0; |
| 8 | int n=arr.length; |
| 9 | for(int i=0;i<n;i++){ |
| 10 | tsum+=arr[i]; |
| 11 | } |
| 12 | int avg1=0,avg2=0; |
| 13 | for(int i=0;i<n;i++){ |
| 14 | s+=arr[i]; |
| 15 | avg1=s/(i+1); |
| 16 | avg2=tsum/n; |
| 17 | if(Math.abs(avg1-avg2)<change){ |
| 18 | change=Math.abs(avg1-avg2); |
| 19 | month=i+1; |
| 20 | } |
| 21 | } |
| 22 | return month; |
| 23 | } |
| 24 | public static void main (String[] args) throws java.lang.Exception |
| 25 | { |
| 26 | int arr[]={1,3,2,3}; |
| 27 | System.out.println(findEarliestMontth(arr)); |
| 28 | } |
| 29 | } |
nothing calls this directly
no outgoing calls
no test coverage detected