解题思路:
注意事项:注意那个经过图像模糊处理之后的图像B
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();//n行
int m = scanner.nextInt();//m列
int[][] B = new int[n][m];
//A矩阵
int[][] A = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
A[i][j] = scanner.nextInt();
}
}
//B矩阵
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
B[i][j] += A[i][j];
} else {
float sum = A[i][j] + A[i - 1][j] + A[i + 1][j] + A[i][j - 1] + A[i][j + 1];
B[i][j] = Math.round(sum / 5f);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(B[i][j] + " ");
}
System.out.println();
}
}
}
0.0分
0 人评分