title: Java lottery repeat program
body: <p>I need this lottery program to repeat itself a certain number of times and then stop, but I am having trouble on where to place the for loop (if that's what I should use). How can I display the percentage of times 0, 1, 2, 3, 4 or 5 numbers matched out of all the runs?</p>
  
  <pre><code>    package assignment5;
      import javax.swing.JOptionPane;
  
      import java.util.Random;
      public class assignment5
      {
  public static void main(String[] args)
  {
      lottery pic=new lottery();
      pic.Get_player_numbers();
      pic.Get_jackpot_number();
      pic.Check_winner ();
      pic.Write_data();
  
  }
      }
      class lottery
      {
  
  int[] picks= new int[5];
  int[] cpick=new int[5];
  int i;
  int j,c;
  int match=0;
  
  void Get_player_numbers ()
  
  {
      int ctemp,cdupflag=0;
      for(j=0;j&lt;=4;++j)
      {
          //YOU DO NOT NEED THE CNUMBERFLAG
          //IF YOU GENERATED THE NUMBERS CORRECLTY, THE COMPUTER WILL NOT GENERATE ONE ABOVE 99 OR LESS THAN 1
         cdupflag=0;
          while(cdupflag==0)
           {
              ctemp = (int)Math.round(Math.random()*99)+1;
              cdupflag=1;
              for(c=0;c&lt;=j;++c)
                 {
                   if(ctemp==cpick[c])
                      {
                       cdupflag=0;
                      }
                  }//inner for loop
              if(cdupflag==1) 
                     cpick[j]=ctemp;
            }
      }
      String Jackpot="User Lottery numbers are: "+"\n";
      //String computer = "";
      for(j=0;j&lt;=4;++j)
      {
          if(j==4)
              Jackpot=Jackpot+cpick[j];   
          else
              Jackpot=Jackpot+cpick[j]+"-";
      }
  
      JOptionPane.showMessageDialog(null,Jackpot,"Output:",JOptionPane.INFORMATION_MESSAGE);
  
  }
  
  //void jackpot()
  void Get_jackpot_number()
  {
  
      int ctemp,cdupflag=0;
      for(j=0;j&lt;=4;++j)
      {
          //YOU DO NOT NEED THE CNUMBERFLAG
          //IF YOU GENERATED THE NUMBERS CORRECLTY, THE COMPUTER WILL NOT GENERATE ONE ABOVE 99 OR LESS THAN 1
         cdupflag=0;
          while(cdupflag==0)
           {
              ctemp = (int)Math.round(Math.random()*99)+1;
              cdupflag=1;
              for(c=0;c&lt;=j;++c)
                 {
                   if(ctemp==cpick[c])
                      {
                       cdupflag=0;
                      }
                  }//inner for loop
              if(cdupflag==1) 
                     cpick[j]=ctemp;
            }
      }
      String Jackpot="Computer Lottery numbers are: "+"\n";
      //String computer = "";
      for(j=0;j&lt;=4;++j)
      {
          if(j==4)
              Jackpot=Jackpot+cpick[j];   
          else
              Jackpot=Jackpot+cpick[j]+"-";
      }
  
      JOptionPane.showMessageDialog(null,Jackpot,"Output:",JOptionPane.INFORMATION_MESSAGE);
  
  }
  
  
  void Check_winner ()
  {
  
      for(int i=0;i&lt;=4;++i)
      {
          for(int j=0;j&lt;=4;++j)
          {
              if(picks[i]==cpick[j])
              {
                  match=match+1;
              }
          }
      }
  
  }
  
  
  void Write_data ()
  {
      String print = "";
  
      if(match==0)
      {
          print=print+"There is no match"+"\n";
          print=print+"please try again "+"\n";
      }
      else
      if(match==1)
      {
          print=print+"There is one match"+"\n";
          print=print+"You won 100 Dollars "+"\n";
      }
      else 
          if(match==2)
          {
              print=print+"There are two matches"+"\n";
              print=print+"You won 1,000 Dollars"+"\n";
          }
          else
              if(match==3)
              {
                  print=print+"There are three matches"+"\n";
                  print=print+"You won 10,000 Dollars "+"\n";
              }
              else
                  if(match==4)
                  {
                      print=print+"There are four matches"+"\n";
                      print=print+"You won 100,000 Dollars "+"\n";
                  }
                  else
                      if(match==5)
                      {
                          print=print+"There are five matches"+"\n";
                          print=print+"You won 1,000,000 Dollars"+"\n";
                      }
      JOptionPane.showMessageDialog(null,print,"Output:",JOptionPane.INFORMATION_MESSAGE);
  }}
  
      //end of class lottery
  </code></pre>