这是我到目前为止。我在结束了和但是输入号码为阵,无尽的循环,它不断循环正常,至于数去为什么我的循环被破坏?二维数组[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