subject

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));
}
}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 14:20, ashl3yisbored
The concept of comes from the acknowledgment that data changes form and often gets copied, moved, and stored in many places. sensitive data often leaves the protection of application databases and ends up in e-mails, spreadsheets, and personal workstation files.
Answers: 3
image
Computers and Technology, 22.06.2019 05:30, Cassandoo
The total revenues for a company are $150,223 and the total expenses were 125,766. if you are calculating the net income, which of these spreadsheets would you use? insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2-b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2+b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2/b3. the formula should be showing in the formula bar. insert a spreadsheet with $150,223 in cell b2 and 125, 766 in cell b3. enter a formula =b2*b3. the formula should be showing in the formula bar.
Answers: 3
image
Computers and Technology, 22.06.2019 06:20, Masielovebug
In what kind of attack can attackers make use of millions of computers under their control in an attack against a single server or network availability confidentiality integrity identity automated attack software? those who wrongfully disclose individually identifiable health information can be fined up to what amount per calendar year? single most expensive malicious attack hipaa what are script kiddies? advanced persistent threat security manager security engineer what level of security access should a computer user have to do their job what process describes using technology as a basis for controlling the access and usage of sensitive data? cybercriminal
Answers: 1
image
Computers and Technology, 22.06.2019 23:00, nicog94
In which part of a professional email should you try to be brief, but highly descriptive?
Answers: 1
You know the right answer?
Language: Java I'd like for my code to print "O" 30% of the time, but it prints "O" 100% of the tim...

Questions in other subjects:

Konu
Mathematics, 27.10.2019 10:43
Konu
Mathematics, 27.10.2019 10:43