-2
그래서 저는이 지뢰 찾기 게임을 만들었고 두 가지 방법 중 하나를 사용하여 배열을 특정 문자로 초기화하고 하나의 메서드로 실제로 게임을 인쇄합니다.2D 배열 및 메서드 호출
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = 0;
int b = 0;
System.out.println("Welcome to Mine Sweeper!");
a = promptUser(in, "What width of map would you like (3 - 20):", 3, 20);
b = promptUser(in, "What height of map would you like (3 - 20):", 3, 20);
eraseMap(new char[b][a]);
simplePrintMap(new char[b][a]);
}
public static int promptUser(Scanner in, String prompt, int min, int max) {
int userInput;
System.out.println(prompt);
userInput = in.nextInt();
while (userInput < min || userInput > max) {
System.out.println("Expected a number from 3 to 20.");
userInput = in.nextInt();
}
return userInput;
}
public static void eraseMap(char[][] map) {
for (int i = 0; i < map.length; ++i) {
for (int j = 0; j < map[i].length; ++j) {
map[i][j] = (Config.UNSWEPT);
}
}
return;
}
public static void simplePrintMap(char[][] map) {
for (int i = 0; i < map.length; ++i) {
for (int j = 0; j < map[i].length; ++j) {
System.out.print(map[b][a] + " ");
}
System.out.println();
}
return;
}
질문에 방법이 eraseMap 및 simplePrintMap입니다 : 여기 내 코드입니다. eraseMap은 배열을 "." 그리고 simplePrintMap은 실제로 배열을 인쇄하기로되어 있습니다. 그래서 3과 4를 입력하면 기간은 3의 너비와 4의 높이가됩니다.
(각 마침표는 공백으로 구분됨).
무엇이 문제입니까? 당신은 무엇을 기대합니까? 주어진 입력에 대해 실제로 얻는 것은 무엇입니까? –