public class Main {
public void solution(int[][] arr1) {
int[][] answer = new int[5][5] ;
int[][] check = new int[5][5];
System.out.println();
}
public static void main(String[] args) {
Main method = new Main();
int[][] arr1 = {{7,4,6,5,9}, {6,1,3,4,5}, {4,8,5,6,9}, {1,3,0,6,4}, {6,4,8,1,7}};
method.solution(arr1);
}
}
// 상. 양옆앞뒤 큰 수 찾기
public class test03 {
public void solution(int[][] arr1) {
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr1[i].length; j++) {
if (i == 0) { // 1행
if (j == 0) { // 1행 - 1열
if (arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else if (0 < j && j < 4) { // 1행 - 2열 ~ 4열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else { // 1행 5열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
}
} else if (0 < i && i < 4) { // 2행 ~ 4행
if (j == 0) { // 2행 ~ 4행 - 1열
if (arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i-1][j] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else if (0 < j && j < 4) { // 2행 ~ 4행 - 2열 ~ 4열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i-1][j] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else { // 2행 ~ 4행 5열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i-1][j] && arr1[i][j] > arr1[i+1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
}
} else { // 5행
if (j == 0) { // 5행 - 1열
if (arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i-1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else if (0 < j && j < 4) { // 5행 - 2열 ~ 4열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i][j+1] && arr1[i][j] > arr1[i-1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
} else { // 5행 5열
if (arr1[i][j] > arr1[i][j-1] && arr1[i][j] > arr1[i-1][j]) {
System.out.print("*");
} else {
System.out.print(arr1[i][j]);
}
}
}
}
System.out.println();
}
}
public static void main(String[] args) {
test03 method = new test03();
int[][] arr1 = {{7,4,6,5,9}, {6,1,3,4,5}, {4,8,5,6,9}, {1,3,0,6,4}, {6,4,8,1,7}};
method.solution(arr1);
}
}
규칙
전체적으로
한 줄 내에서