lundi 5 décembre 2016

Picking random Variable in java through Array

public class HatP {

    public static void main(String[] args)
    {
        int size=4;
        char[] hats = new char[]{'B','B','W','W','W'};
        char[] anArray = new char[4];
        while( true){
            Random rand= new Random();
            int  num=rand.nextInt(5);
            for(int i=0;i<size;i++)
            {
                anArray[i]=hats[num];
            }
            break;
        }
        System.out.print(anArray);
    }
}

Im wondering why I can't get random result through an array I declared!!

The result I get is only WWWW OR BBBB.. :(

What I looking for is a list that takes many values like wwwbb or wbbww somthing like this .




Aucun commentaire:

Enregistrer un commentaire