public class Tester2 {
public static void main(String[] args) {
int[][] image = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
// assume a rectangular image
int[][] smooth = new int[image.length][image[0].length];
int sum = 0;
int col = 0;
// Compute the smoothed value for non-edge locations in the image.
for (int row = 1; row < image.length - 1; row++) {
for (col = 1; col < image[row].length - 1; col++) {
sum = image[row - 1][col - 1] + image[row - 1][col] + image[row - 1][col + 1] +
image[row][col - 1] + image[row][col] + image[row][col + 1] +
image[row + 1][col - 1] + image[row + 1][col] + image[row + 1][col + 1];
}
smooth[row][col] = sum/9;
}
// write out the input
for (int row = 0; row < image.length; row++) {
for (int col1 = 0; col1 < image[row].length; col1++) {
System.out.print(image[row][col1] + " ");
}
System.out.println();
}
for (int row = 0; row < image.length; row++) {
for (int col1 = 0; col1 < image[row].length; col1++) {
System.out.print(image[row][col1] + " ");
}
System.out.println();
}
}
}
Я хочу напечатать новый массив. Новый массив был создан с помощью:Печать № изображения Массивы
sum = image[row-1][col-1] + image[row-1][col] + image[row-1][col+1] +
image[row][col-1] + image[row][col] + image[row][col+1] +
image[row+1][col-1] + image[row+1][col] + image[row+1][col+1]
Что можно сделать, чтобы распечатать новый массив?
не могли бы вы использовать System.out.print (гладкая [строка] [ col1] + ""); распечатать новый массив? – nullPointer