mercredi 16 mars 2022

If statement not printing every time given the Random condition

if-statement not printing every time even though the condition is true, rather randomly prints no matter which random element of the array is outputted

{   
    int [] a = new int [] {1,2,3,4,5,6,7,8};
    System.out.println("Random number: " +a[new Random().nextInt(a.length)]);
    if(a[new Random().nextInt(a.length)]== 0 || a[new Random().nextInt(a.length)]== 1 || a[new Random().nextInt(a.length)]== 2 ) 
    {
        System.out.println("Congratulations, you recieved 4 Kunai's");
    }



Aucun commentaire:

Enregistrer un commentaire