我正在为学校的项目工作,但是无法理解这个问题。请注意,我非常初级。
我有一个二维数组叫做tickets[19][6]
,其中每张彩票有6个整数,共有20张彩票。
我试图将这20张彩票与一个名为winner[5]
的、包含6个数字的普通数组进行比较,该数组是从一个 .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;
}
}
}
for
循环。可能需要三个嵌套循环。(好吧,重新阅读你的问题后,可能只需要两个嵌套循环。) - Hot Licks