I am a newbie to computer science, and I am having difficulty understanding my professor's instructions. This is what it is:
1. Declare a double array size 100.
2. Fill out the array with 1 if a random value is greater than 0.5 else 0
3. Print the number of 0's that are in the array
And I have been stuck for hours, with no clue how to do it, tutoring center is occupied...
public class DoubleArray {
public static void main(String [] args) {
double [] a = new double[100];
for (int i= 0; i<a.length;i++)
if (Math.random()>0.5) {
a[i]=1;
System.out.println("1");
}
else a[i]=0;
{
System.out.println("0");
}
}
}
I know this is wrong, as it doesn't even include the counter of 0's, but I have no idea to use random numbers, and an array, and a for loop, and if/else, and a counter all at once.
Please help as much as you can :(
Aucun commentaire:
Enregistrer un commentaire