# 题目描述

Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 surrounding cells and itself. If a cell has less than 8 surrounding cells, then use as many as you can.

# Java

`class Solution {public int[][] imageSmoother(int[][] M) {        int[][] results = new int[M.length][M.length];        for (int i = 0; i < M.length; i++) {            for (int j = 0; j < M.length; j++) {                int num = 0;                int sum = 0;                for (int k = i - 1; k <= i + 1; k++) {                    for (int f = j - 1; f <= j + 1; f++) {                        if (k >= 0 && f >= 0 && k < M.length && f < M.length) {                            num++;                            sum += M[k][f];                        }                    }                }                results[i][j] = sum / num;            }        }        return results;    }}`