```
public class Solution {
public double findMaxAverage(int[] nums, int k) {
int max = 0;
for (int i = 0; i < k; i++) max += nums[i];
for (int i = 0, j = k, temp = max; i < nums.length - k; i++, j++) {
temp += nums[j] - nums[i];
max = Math.max(temp, max);
}
return (double)max / k;
}
}
```