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 04:40
Amain idea is supported, explained, or expanded on with a numbers b. a concluding statement c. details d. a topic sentence. im e paragraphs reset nex next
Answers: 2
Computers and Technology, 22.06.2019 09:50
Assume that you have an sorted array of records. assume that the length of the array (n) is known. give two different methods to search for a specific value in this array. you can use english or pseudo-code for your algorithm. what is the time complexity for each algorithm and why?
Answers: 1
Computers and Technology, 22.06.2019 21:00
Kirk found a local community college with a two-year program and he is comparing the cost with that of an out-of-state two-year school. what is the expected total cost for one year at the local community college if kirk lives at home? what is the expected total cost for one year at the out-of-state school if kirk lives on campus?
Answers: 2
Computers and Technology, 23.06.2019 07:30
Which option allows you to view slides on the full computer screen?
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...
Mathematics, 02.02.2021 05:10
Computers and Technology, 02.02.2021 05:10
Mathematics, 02.02.2021 05:10
History, 02.02.2021 05:10
History, 02.02.2021 05:10
Physics, 02.02.2021 05:10
English, 02.02.2021 05:10
Mathematics, 02.02.2021 05:10
Physics, 02.02.2021 05:10
Mathematics, 02.02.2021 05:10
Chemistry, 02.02.2021 05:10
Mathematics, 02.02.2021 05:10