我正在爲一所學校的項目工作,但無法弄清楚這一點。我是一個非常初級的初學btw。如何將6個整數的數組與一個2d的整數數組[19] [5]進行比較?
我有一個叫做tickets[19][6]
的二維數組,每張票中有6張票。 我試圖將這20張票與一個常規的整數數組進行比較,這6個數字叫做winner[5]
,我從.txt文件中讀取這些票。
兩個陣列說明如下:
public static int[] winner = new int[5]
public static int[][] tickets = new int[19][5]
請記住我是很新的這一點,我感謝所有幫助提前!
編輯這是我用來分配用戶輸入到我的2D數組的循環,當我經歷整個事情時,它是一個無限循環。我認爲編寫代碼會更多....好吧,寫作!似乎更像目前爲止的調試技巧。
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;
}
}
}
你是什麼意思,「比較」?測試平等? – 2012-04-23 00:29:07
我相信測試是平等的。我試圖比較獲勝者[]和門票[] [],目的是通過搜索門票[] []來獲勝[] – BBradshaw1 2012-04-23 00:38:23
您將使用所謂的「迭代」 - 「for '循環,例如。可能有3個嵌套循環。 (好吧,可能是2個循環,嵌套,重新讀你的問題。) – 2012-04-23 00:39:21