5
What does that mean Math.random() > 0.5;
in a boolean
?
Here is an example:
class Pro {
public static void main(String[] args) {
int numero = 10;
boolean[] array = new boolean[numero];
for(int i= 0; i< array.length; i++) {
array[i] = Math.random() > 0.5;
System.out.print(array[i] + "\t");
}
}
}
In this case it would be if the value of the traversed array no is less than 0.5 ?
– user40803
It is not the value of the array, but the value of the comparison between a random number and 0.5
– Weslley Tavares
The value generated in the Random?
– user40803
Yes. You have an array that stores bolean values, right? Each iteration inside the for will take care of checking whether the number that was randomly generated is less than or greater than 0.5. Depending on the value obtained, the value of that position (in this case, the position will be determined by the integer
i
) will betrue
orfalse
.– Weslley Tavares