자바 질문드립니다
조회수 517회
아래의 코드에서 제가 3과 6을 입력한다면 출력문 상의 3,6 즉 4,7 자리의 모양이 별이라면 근처 붙어있는 별모양이 다 지워지게 하고싶습니다. 지금 상태는 주변 동서남북만 지워지게 했는데 더이상 어떻게 나아가야할지 모르겠네요
package candy;
import java.util.Scanner;
public class Candy { public static void main(String[] args) { int star = 11; int slash = 12; int blank = 13; int pointI = 0; int pointJ = 0; int cnt = 0; boolean TF = true; boolean TF1 = true; int[][] array = new int[11][11]; boolean[][] check = new boolean[11][11] ; int[] dx = {0,1,0,-1}; int[] dy = {1,0,-1,0};
Scanner scan = new Scanner(System.in);
for (int i = 0; i < array.length; i++) { // 배열 만들기
for (int j = 0; j < array[i].length; j++) {
int ranNum = (int) (Math.random() * 2);
if (i == 0) {
array[i][j] = j - 1;
} else if (i > 0 && j > 0 && ranNum == 0) {
array[i][j] = star;
} else if (i > 0 && j > 0 && ranNum == 1) {
array[i][j] = slash;
}
}
array[i][0] = i - 1;
}
///
while(TF) {
for (int i = 0; i < array.length; i++) { // 배열출력
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] == slash) {
System.out.print("/");
} else if (array[i][j] == star) {
System.out.print("*");
} else if (array[i][j] == -1) {
System.out.print(" ");
} else if (array[i][j] == blank) {
System.out.print(" ");
} else {
System.out.print(array[i][j]);
}
}
System.out.println();
}
///
//
System.out.print("col[i]>>");
int scanNum1 = scan.nextInt();
System.out.print("row[j]>>");
int scanNum2 = scan.nextInt();
scanNum1 +=1;
scanNum2 +=1;
/*
int[] dx = {0,1,0,-1};
int[] dy = {1,0,-1,0};*/
while(TF1) {
if(array[scanNum1][scanNum2] == star) {
check[scanNum1][scanNum2]=true;
for(int i = 0; i<4; i++) {
int _x = scanNum1 + dx[i];
int _y = scanNum2 + dy[i];
if(_x >0 && _y>0 && _x<11 && _y<11) {
if(array[_x][_y]==star && check[_x][_y] ==false) {
check[_x][_y]=true;
array[_x][_y] = blank;
}
}
}
cnt++;
}
if(cnt==10) {
TF1 =false;
}
}
}
}
}
댓글 입력