2014-04-29 5 views
0

복권 프로그램을 만들어 0-9 사이에서 3 개의 숫자를 무작위로 생성 한 다음 무작위로 3 개의 우승 숫자를 생성했습니다. 프로그램이 승자를 표시하는 방법 (일부가있는 경우)을 만들고 복권 당첨자 수를 표시하는 방법에 대한 도움이 필요합니다.복권 당첨자 표시

는 는

그래서 같은 : 당신은 루프에 대한 또 다른 원하는 여기에 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(); 
    } 


} 
} 
+1

rand.nextInt (7-0 일)의 rand.nextInt (8) 이상의 구문 다르지 않다 후자는 –

답변

1

된다 수상자 : 수상자의

PERSON1

person5

번호 . 같은 뭔가 :

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."); 
+0

가 드디어 일을 가지고 감사 쉽게 읽을 수 – user3350626