我正在为学校做一个项目,但无法弄清楚。顺便说一句,我是一个非常初级的初学者。
我有一个二维数组,称为tickets[19][6]
20 张票,每张票有 6 个整数。我正在尝试将这 20 张票与具有 6 个数字的常规整数数组进行比较winner[5]
我从 .txt 文件中读取的。
两个数组的说明如下:
public static int[] winner = new int[5]
public static int[][] tickets = new int[19][5]
请记住,我对此很陌生,我提前感谢任何帮助!
编辑这是我用来将用户输入分配给我的二维数组的循环,当我经历整个事情时才意识到这是一个无限循环。我认为编写代码会更多......好吧,写作!到目前为止,似乎更像是调试的艺术。
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;
}
}
}