これまで私が持っていたことは次のとおりです。あなたが割り当てたとき、私はで終わると配列の番号を入力するの無限ループは、しかし、それは限り数字はこれはマイナーなものであるループが壊れているのはなぜですか? 2d array of [20] [6]
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;
}
}
}
このコードで何をしようとしていますか?私はあなたのループが "無限"だとは思わない、それはちょうど終わるのに長い時間がかかる。 – Bernard
2d配列をユーザー生成番号で埋めようとしていますので、2次元配列を通常の配列と比較し、一致するものがあるかどうかを確認して勝者にします。私は停止する前に、1〜20回、5回、サイクルを巡って行きました*編集*今度は2回サイクルして終了します... wth – BBradshaw1
'ticketCount'は最終的に' 21'の値に達し、 'number'は最終的に' 7'の値に達し、 'ticketCount'をインクリメントします。内部ループを使用するようにループを再設計することができます。 – Bernard