Computers and Technology, 18.02.2021 04:30 risolatziyovudd
Language: Java
I'd like for my code to print "O" 30% of the time, but it prints "O" 100% of the time. How can I fix that?
Code:
public class PetriDish {
private boolean[][] grid;
public PetriDish()
{
// Formula: (int)(Math. random() * (max - min + 1) + min);
int row = (int)(Math. random() * (30 - 5 + 1) + 5);
int column = (int)(Math. random() * (30 - 5 + 1) + 5);
boolean[][] grid2 = new boolean [row][column];
for(int i = 0; i < row; i++)
{
for(int j = 0; j < column; j++)
{
grid2[i][j] = Math. random() < 0.30;
}
}
grid = grid2;
}
public void showGrid()
{
for(int row = 0; row < grid. length; row++)
{
for(int column = 0; column < grid[0].length; column++)
{
if (grid[row][column] = true)
System. out. print("O"); //true state
else
System. out. print("."); //False State
}
System. out. println();
}
}
public int numNeighbors(int row, int col)
{
int count = 0;
for(int i = row - 1; i <= row + 1 ; i++)
{
for(int j = col - 1; j <= col + 1; j++)
{
if ((i >= 0) && (i < grid. length))
{
if ((j >= 0) && (j < grid. length))
{
if ((i != row ) && (j != col))
{
if (grid[i][j] = true)
count++;
}
}
}
}
}
return count;
}
public static void main(String args[])
{
PetriDish p = new PetriDish();
p. showGrid();
/*Change the (4,4) to be a random valid value within the grid*/
System. out. println(p. numNeighbors(0,0));
}
}
Answers: 1
Computers and Technology, 22.06.2019 10:30
Think about a recent customer service experience - either positive or negative. write a brief summary of that experience. now think about those four characteristics we look for in customer service representatives. how did the representative in your example stack up? write down your answer and give specific examples.
Answers: 1
Computers and Technology, 22.06.2019 19:10
10. when you create a pivottable, you need to specify where to find the data for the pivottable. is it true
Answers: 2
Computers and Technology, 22.06.2019 21:00
The average cost of one year at a private college in 2012-2013 is $43,289. the average grant aid received by a student at a private college in 2012-2013 is $15,680. what is the average student contribution for one year at a private college in 2012-2013?
Answers: 3
Computers and Technology, 23.06.2019 22:30
The output voltage of a power supply is assumed to be normally distributed. sixteen observations are taken at random on voltage are as follows: 10.35, 9.30, 10.00, 9.96, 11.65, 12.00, 11.25, 9.58, 11.54, 9.95, 10.28, 8.37, 10.44, 9.25, 9.38, and 10.85
Answers: 1
Language: Java
I'd like for my code to print "O" 30% of the time, but it prints "O" 100% of the tim...
Health, 02.11.2020 01:00
English, 02.11.2020 01:00
History, 02.11.2020 01:00
History, 02.11.2020 01:00
History, 02.11.2020 01:00
English, 02.11.2020 01:00
English, 02.11.2020 01:00
Mathematics, 02.11.2020 01:00
Advanced Placement (AP), 02.11.2020 01:00
Biology, 02.11.2020 01:00
History, 02.11.2020 01:00