Question: Write a java program that receives m and n as the number of rows and columns of the grid, respectively. In the second line, the

Write a java program that receives m and n as the number of rows and columns of the grid, respectively. In the second line, the user inputs an integer, b, showing the number of bombs placed in the grid. It then follows by b lines of input from the user, each referring to the row and column index of each one of the bombs.

After receiving grid dimensions, the number of bombs, and bomb locations, you will need to display (print) the completed grid showing the bomb cells with * and safe cells with the number of neighboring bombs to that cell.

This is the code i have but i am getting an errorWrite a java program that receives m and n as the number

 package assignmentTwo; 

import java.util.Scanner;

public class minesweeper {

static boolean isValid(int row, int col, int[][]grid){

if (row >= 0 && row= 0 && col

return true;

}

return false;

}

public static void main(String[]args) {

Scanner sc = new Scanner(System.in);

int m = sc.nextInt();

int n = sc.nextInt();

int grid[][] = new int[m][n];

for (int i=0; i

for (int j=0; j

grid[i][j]=0;

}

}

int b = sc.nextInt();

for (int i =0; i

int row = sc.nextInt();

int col = sc.nextInt();

grid[row][col]=-1;

}

if (isValid (row -1, col -1, grid)) {

if(grid[row -1][col -1]!=-1) {

grid[row -1][col -1]++;

}

}

if (isValid(row -1, col, grid)) {

if(grid[row -1][col]!=-1) {

grid[row -1][col]++;

}

}

if (isValid(row -1, col +1, grid)) {

if(grid[row -1][col +1]!=-1) {

grid[row -1][col +1]++;

}

}

if (isValid(row, col -1, grid)) {

if(grid[row][col -1]!=-1) {

grid[row][col -1]++;

}

}

if (isValid(row, col +1, grid)) {

if(grid[row][col +1]!=-1) {

grid[row][col +1]++;

}

}

if (isValid(row +1, col -1, grid)) {

if(grid[row +1][col -1]!=-1) {

grid[row +1][col -1]++;

}

}

if (isValid(row +1, col, grid)) {

if(grid[row +1][col]!=-1) {

grid[row +1][col]++;

}

}

if (isValid(row +1, col +1, grid)) {

if(grid[row +1][col +1]!=-1) {

grid[row +1][col +1]++;

}

}

System.out.println();

for (int i = 0; i

for (int j = 0; j

if (grid[i][j]== -1) {

System.out.print("* ");

}

else {

System.out.print(grid[i][j]+" ");

}

}

System.out.println();

}

}

}

stepik.org Problem Set- Step 4 -Stepik The Resting Membrane Potent... juxtamedullary nephron ion ex... EC Code Challenge-Write a program, test using stdin stdout Wrong Debug your code with your own inputs! Failed test 1* wrong answer Input: 2 Your output: Correct output: Hide Time Limit: 8 seconds Memory Limit: 256 MB 3import java.util.Scanner; 4 class Bombs static boolean isValid(int row, int col, int[][] grid) ( 10 if (row >= 0 && row = 0 && col grid[row ]. ength )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!