mercredi 3 octobre 2018

How can i get 4 random values out an array Java

i am new to java programming and now i want to get 4 random values out of an string array i have the following code but if i run my code i get the same random color 4 times.

 String [] color = {"red","blue","yellow", "purple", "black"};
       int random = (int) (4*  Math.random());
        String randomColors = (color[random]);
        for (int i = 0; i <4 ; i++) {
            System.out.println(randomColors);
        }

does anyone know how i can fix this. And again i am new to programming.




Aucun commentaire:

Enregistrer un commentaire