题目
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int m = sc.nextInt();int[][] f = new int[n][m];for(int i=0;i<n;i++) {for(int j=0;j<m;j++) {f[i][j] = sc.nextInt();}}for(int i=0;i<n;i++) {for(int j=0;j<m;j++) {if(f[i][j] == 1) {System.out.print(9+" ");}else {int ans = 0;for(int a=i-1;a<=i+1;a++) {for(int b=j-1;b<=j+1;b++) {if(a<0 || a>=n || b<0 || b>=m)continue;if(f[a][b] == 1)ans++;}}System.out.print(ans+" "); }}System.out.println();}sc.close(); }
}