この方法でスコープの問題が発生しています。ループが終了したら、wileループで構築された配列を確実に返す方法がわかりません。このメソッドは、Reversiゲームボードを作成するために偶数番号を取得するように設計されています。 whileループは、ボードのサイズが正しいことを保証するために配置されています。 returnステートメントをループ内に配置すると、エラーが発生します。私の質問は、whileループで作成された配列を返す方法です。下部のreturnステートメントは "シンボルを見つけることができません"というエラーを投げています。中心にパラメータを持つNxN行列を作成する
コードブロック内で作成された変数はそのブロックのみ、すなわちに住んでいるためだpublic static int [][] GetGameBoard(){
//initalizing local.
int sizeChoice = 1;
int black = 1;
int white = 2;
//creating scanner object.
Scanner input = new Scanner(System.in);
//while loop to ensure choice is correct.
while((sizeChoice%2) != 1 && sizeChoice < 4){
//asing user for input.
System.out.println("Please enter the size of the board you want!");
System.out.print("The size must be > 4 and an even number: ");
System.out.println("\n");
sizeChoice = input.nextInt();
if (sizeChoice%2 == 0 && sizeChoice >= 4){
System.out.println("You have chosen a " + sizeChoice + "x"
+ sizeChoice + " board.");
//creating board.
int theBoard[][] = new int[sizeChoice][sizeChoice];
//intializing half way points for board center
int halfWay1 = (sizeChoice/2);
int halfWay2 = (sizeChoice/2) + 1;
theBoard[halfWay1][halfWay1] = black;
theBoard[halfWay1][halfWay2] = white;
theBoard[halfWay2][halfWay1] = white;
theBoard[halfWay2][halfWay2] = black;
}
else if(sizeChoice%2 != 0){
System.out.println("Incorrect input you must choose an even,"
+ "number!");
}
else if (sizeChoice < 4){
System.out.println("Incorect size you must choose a size board"
+ " >= 4.");
}//end of if/else's
}//end of while.
return theBoard;
}// end of GetGameBoard
あなたの質問がある場合、あなたの質問はあまり明確ではありません。 –