vendredi 24 septembre 2021

Trying to create a program that picks 7 digits and tries it on the lottery, is there any easier way to do this?

So my problem is that I'm a lazy dude and also relearning Java from my high school days. And I want to code a program that can basically take 7 "quick pick" randomly generated numbers, and 7 winning numbers and keep looping it over and over again until it hits and counts the number of loops it did before it hit. But I can't figure out an easier way to check if each number matches up with a winning number without spending an hour or two writing if statements for each scenario. Heres my code:

class chancesofLotterywin {
  
  public static void main(String[] args){
    
    //Quick Pick
    double qp1 = 1;
    double qp2 = 1;
    double qp3 = 1;
    double qp4 = 1;
    double qp5 = 1;
    double qp6 = 1;
    double qp7 = 1;
    
    //Winning Numbers
    double win1 = 1;
    double win2 = 1;
    double win3 = 1;
    double win4 = 1;
    double win5 = 1;
    double win6 = 1;
    double win7 = 1;
   
    for(int i = 0;;i++){
      
      qp1 = Math.floor((Math.random()*50)+1);
      qp2 = Math.floor((Math.random()*50)+1);
      qp3 = Math.floor((Math.random()*50)+1);
      qp4 = Math.floor((Math.random()*50)+1);
      qp5 = Math.floor((Math.random()*50)+1);
      qp6 = Math.floor((Math.random()*50)+1);
      qp7 = Math.floor((Math.random()*50)+1);
      
      win1 = Math.floor((Math.random()*50)+1);
      win2 = Math.floor((Math.random()*50)+1);
      win3 = Math.floor((Math.random()*50)+1);
      win4 = Math.floor((Math.random()*50)+1);
      win5 = Math.floor((Math.random()*50)+1);
      win6 = Math.floor((Math.random()*50)+1);
      win7 = Math.floor((Math.random()*50)+1);
      
      
      if (qp1 == win1){
        if (qp2 == win2){
          if (qp3 == win3){
            if (qp4 == win4){
              if (qp5 == win5){
                if (qp6 == win6){
                  if(qp7 == win7){
                    System.out.println(qp1 + " " + qp2 + " " + qp3 + " " + qp4 + " " + qp5 + " " + qp6 + " " + qp7);
                    System.out.println(win1 + " " + win2  + " " + win3 + " " + win4  + " " + win5 + " " + win6 + " " + win7 );
                    System.out.println(i);
                    break;
                  }else{}
                }else if(qp6 == win7){
                  if(qp7 == win6){
                  System.out.println(qp1 + " " + qp2 + " " + qp3 + " " + qp4 + " " + qp5 + " " + qp6 + " " + qp7);
                  System.out.println(win1 + " " + win2  + " " + win3 + " " + win4  + " " + win5 + " " + win6 + " " + win7 );
                  System.out.println(i);
                  break;
                }else{}
                }else{}
              }else if (qp5 == win6){
                if (qp6 == win5){
                
              }else if (qp5 == win7){
                
              }else{}
            }else if (qp4 == win5){
              
            }else if (qp4 == win6){
              
            }else if (qp4 == win7){
              
            }else{}
          }else if (qp3 == win4){
            
          }else if (qp3 == win5){
            
          }else if (qp3 == win6){
            
          }else if (qp3 == win7){
            
          }else{}
        }else if (qp2 == win3){
          
        }else if (qp2 == win4){
          
        }else if (qp2 == win5){
          
        }else if (qp2 == win6){
          
        }else if (qp2 == win7){
          
        }else{}
      }else if(qp1 == win2){
        
      }else if (qp1 == win3){
        
      }else if (qp1 == win4){
        
      }else if (qp1 == win5){
        
      }else if (qp1 == win6){
        
      }else if (qp1 == win7){
        
      }else{}
        /*if (((qp2 == win1) || (qp2 == win2) || (qp2 == win3) || (qp2 == win4) || (qp2 == win5) ||(qp2 == win6) || (qp2 == win7))){
          if(((qp3 == win1) || (qp3 == win2) || (qp3 == win3) || (qp3 == win4) || (qp3 == win5) ||(qp3 == win6) || (qp3 == win7))){
            if(((qp4 == win1) || (qp4 == win2) || (qp4 == win3) || (qp4 == win4) || (qp4 == win5) ||(qp4 == win6) || (qp4 == win7))){
              if(((qp5 == win1) || (qp5 == win2) || (qp5 == win3) || (qp5 == win4) || (qp5 == win5) ||(qp5 == win6) || (qp5 == win7))){
                if(((qp6 == win1) || (qp6 == win2) || (qp6 == win3 || (qp6 == win4) || (qp6 == win5) ||(qp6 == win6) || (qp6 == win7)))){
                  if(((qp7 == win1) || (qp7 == win2) || (qp7 == win3) || (qp7 == win4) || (qp7 == win5) ||(qp7 == win6) || (qp7 == win7))){
                    System.out.println("check 7");
                    System.out.println(qp1 + " " + qp2 + " " + qp3 + " " + qp4 + " " + qp5 + " " + qp6 + " " + qp7);
                    System.out.println(win1 + " " + win2  + " " + win3 + " " + win4  + " " + win5 + " " + win6 + " " + win7 );
                    System.out.println(i);
                    break;
                  }
                }
              }
            }
          }
        }*/
      }
    }
  }
}

A lot of it is incomplete because I can't be asked to code every scenario. The commented part out is my previous solution, but it has a problem of having 1 winning number equalling multiple quick pick numbers.

Is there any easier way of doing this? Also please go light on the technical mumbo Jumbo, the most I've relearned Java up to was do/while loops.

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire