我创建了一个抽奖程序,在0-9之间随机生成3个数字,然后随机生成3个中奖号码。我需要有关如何让节目显示获胜者(如果有的话)的帮助,并显示彩票赢了多少。
类似于: 优胜者:
PERSON1
person5
获奖者人数:2
这是我的程序
import java.util.Random;
public class TwoDArray
{
public static void main(String[] args)
{
int[][] table = new int[50][3];
int[][] win = new int[1][3];
Random rand = new Random();
int i = 1;
// Load the table with values
for (int row=0; row < table.length; row++)
for (int col=0; col < table[row].length; col++)
table[row][col] = rand.nextInt(7-0 +1)+0 + col;
// Load the winning Values
for (int row=0; row < win.length; row++)
for(int col=0; col < win[row].length; col++)
win[row][col] = rand.nextInt(7-0 +1)+0 + col;
// Print the table of People
for (int row=0; row < table.length; row++)
{
System.out.print("Person" + i++ +":\t");
for (int col=0; col < table[row].length; col++)
System.out.print(table[row][col] + "\t");
System.out.println();
}
//Print the Winning Numbers
for (int row=0; row < win.length; row++)
{
System.out.print("\nThe winning numbers are:\t");
for(int col=0; col < win[row].length; col++)
System.out.print(win[row][col] + "\t");
System.out.println();
}
}
}
答案 0 :(得分:1)
你想要另一个for循环。类似的东西:
int counter = 0;
for (int i =0; i < table.length; i++){
if (table[i][0] == win[0][0] && table[i][1] == win[0][1] && table[i][2] == win[0][2])
{
counter++;
System.out.println("Person " + i);
}
}
System.out.println("There were " + counter + " winners.");