mercredi 11 juillet 2018

Set.contains(Integer.parseInt(Number1.getText()) allways returns true even when the value is wrong

Problem:

A HashSet has 7 (Int) Values in it , if i try to test if it contains a Number (ex. 15) it will return true even if it does not contain a 15.

The Code:

Here I fill up the Set: (its called genLotto)

void lottoGen() {
    genLotto.add(0);
    while(genLotto.size() <7) {
        int i = ((int)(Math.random()*49)+1);
        if(!genLotto.contains(i)){
            System.out.println("Number"+genLotto.size()+" is "+i);
            genLotto.add(i);
        }else{
        }
    }   
}

The Code the is problematic:

public void actionPerformed(ActionEvent arg0) {
            if(genLotto.contains(Integer.parseInt(Zahl1.getText()))){
                Zahl1.setBackground(Color.GREEN);
            }else {
                Zahl1.setBackground(Color.RED);
            }

Aucun commentaire:

Enregistrer un commentaire