私は学校のプロジェクトに取り組んでいますが、これを理解できません。私は非常に初心者レベルの初心者です。
tickets[19][6]
各チケットに 6 つの int を持つ 20 チケットという 2 次元配列があります。winner[5]
これらの 20 個のチケットを、.txt ファイルから読み取った、6 つの数字を持つ通常の int 配列と比較しようとしています。
両方の配列は次のように記述されています。
public static int[] winner = new int[5]
public static int[][] tickets = new int[19][5]
私はこれに非常に慣れていないことを覚えておいてください。事前に助けていただければ幸いです。
編集これは、ユーザー入力を2次元配列に割り当てるために使用しているループです。全体を調べたときに、それが無限ループであることに気付きました。コードを書くことはもっと….まあ、書くことだと思っていました!これまでのところ、デバッグの芸術に似ているようです。
static void ticketNumberArray(){
int number = 1; // which of the six numbers you need from the ticket
int ticketCount = 1; // which ticket (out of 20) you are currently on
while(ticketCount<21){ // sentinel controlled while loop,
// will continue until the twentieth ticket is entered
System.out.println("Please type number " +number+ " of ticket number " +ticketCount+ ".");
//asks for the numbers of the ticket your currently on
Scanner keyboard = new Scanner(System.in); // initiates a scanner variable
int ticketNumber = keyboard.nextInt(); // assigns user input to the double variable ticketNumber
// and initializes as a double
tickets[ticketCount-1][number-1]=ticketNumber; // assigns user input into a 2-d array
number++; //Sentinel variable
if(number==7){ //loop that controls the ticket count, every 6 numbers ='s one ticket
ticketCount++;
number=1;
}
}
}