這是我到目前爲止。我在結束了和但是輸入號碼爲陣,無盡的循環,它不斷循環正常,至於數去爲什麼我的循環被破壞?二維數組[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 2012-04-23 01:32:20
我試圖與用戶生成的數字,所以我可以在二維數組比較有規律的排列和檢查,看看是否有任何比賽,使得比賽分出勝負,填補了二維數組。這肯定是無止境的,我整個週期,1到20去了,之前5次我停了下來。*編輯*現在循環兩次,然後終止......問心無愧 – BBradshaw1 2012-04-23 01:35:47
'ticketCount'最終應達到的'21'值和終止因爲'number'最終會達到'7'的值,從而增加'ticketCount'。您可能需要重新設計您的循環以使用內部循環。 – Bernard 2012-04-23 01:44:44