so I have to do this problem, but these arrays are confusing me because I’m not sure how to combine a boolean with arrays and then have them properly organized. I know this is a completely incorrect code, but I really don't know what to do. These are the instructions:
Declare a 2D boolean array of size 5 and 10
Fill out the array with true if a random value is 0.5 else false
Print number of false in the array
Print the array one line per row
Print the array indexes one line per row
Print only the index of the cells with true value
public class DoubleArray {
public static void main(String [] args) {
double [][] a = new double[10][15];
int zeroCount = 0;
for (int i= 0; i<a.length;i++)
{
if (Math.random()>0.5) {
System.out.println("1" + "\t" + "1");
}
else
{
zeroCount++; // increment
System.out.println("0" + "\t" + "0");
}
}
System.out.println("Number of zeros is " + zeroCount);
}
}
Aucun commentaire:
Enregistrer un commentaire