mercredi 9 décembre 2020

Search for duplicated element in an Array randomly filled in Java

Hi i have a question i need to check if in an Array who was randomoly filled if there are some element who are duplicated?

this is my random generator:

    public static void creaGiocator1(String Giocatori[]){
    String[]Nomi={"Kobe","Michael","LeBron","James","Kawhi","Wilt","Stephen","Tim","Marco","Bill"};
    String[]Cognomi={"Bryant","Jordan","James","Harden","Leonard","Chamberlain","Curry","Duncan","Belinelli","Russell"};
    int max=Nomi.length-1;
    int min=0;
    int range=max-min+1;
    int randNomi;
    int randCognomi;
    boolean salcazzi=true;
    for (int i=0 ;i<Giocatori.length ;i++ ) {
      randNomi=(int)(Math.random() * range) + min;
      randCognomi=(int)(Math.random() * range) + min;
      for (int j=0 ;j<i ;j++ ) {
        if (Nomi[randNomi]+" "+Cognomi[randCognomi]!=Giocatori[j]) {
          salcazzi=false;
        }
      }
      if (!salcazzi){
        Giocatori[i]=Nomi[randNomi]+" "+Cognomi[randCognomi];
        salcazzi=true;
      }

    }
    for (int picone=0;picone<Giocatori.length;picone++){
      if(Giocatori[picone]=)
    }
  }



Aucun commentaire:

Enregistrer un commentaire