Java method that accepts (so you don't need to make an array for it) a 2d array.of unknown row and column length. it functions like minesweeper but a lot smaller scale. basically in this case the 0's in the array indicate nothing an 8's indicate a mine. So squares surrounding the 8 (mine) indicate how many mines are adjacent to it. So if there are two mines adjacent to one squre it will show two.so like this.
0 1 1 2 1 1
0 1 8 2 8 1
0 1 1 2 1 1
0 0 0 0 0 0
public static void findMinesweeper(int[][] array) {public class MineSweeper {
public static void findMinesweeper(int[][] array) {
int r, c, count;
for(int i = 0; i < array.length; ++i) {
for(int j = 0; j < array[i].length; ++j) {
if(array[i][j] != 8) {
count = 0;
r = i-1;
c = j-1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i-1;
c = j;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i-1;
c = j+1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i;
c = j-1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i;
c = j+1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i+1;
c = j-1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i+1;
c = j;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
r = i+1;
c = j+1;
if(r < array.length && r >= 0 && c < array[r].length && c >= 0 && array[r][c] == 8) {
count++;
}
array[i][j] = count;
}
}
}
}
public static void main(String[] args) {
int[][] mines = {{0, 0, 0, 0, 0, 0}, {0, 0, 8, 0, 8, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
findMinesweeper(mines);
for(int i = 0; i < mines.length; ++i) {
for(int j = 0; j < mines[i].length; ++j) {
System.out.print(mines[i][j] + "\t");
}
System.out.println();
}
}
}

Java method that accepts (so you don't need to make an array for it) a 2d...
java
Write methods for 2d 1. a method to calculate the sum of a 2d double array 2. a method to calculate the sum of each row of a 2d double array 3. a method to calculate the sum of each column of a 2d double array 4. a method to calculate the average of a 2d double array 5. a method to calculate the average of each row of a 2d double array 6. a method to calculate the...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
Java programming: I need to create a method that is given a 2D char array and a String that returns a part of the original 2D array. The input string will tell the method which rows from the input array need to be returned. For example, a 5x5 char array input along with a string "0 4" would return rows 1 and 5 of the input array. The String input will always be numbers divided by spaces and will not...
The last element in each array in a 2D array is incorrect. It’s your job to fix each array so that the value 0 is changed to include the correct value. In the first array, the final value should be the length of the first array. In the second array, the final value should be the sum of the first value, and the second to last value in the array. In the third array, the final value should be the...
How to replace elements in a 2D array? Okay so for my program, I am trying to create a fish tank. My program is to generate 4 different FISH: ><))'> in a tank of tilde (~) characters. The tank is a 2D array of 8 rows and 32 columns so it would look like ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for one of the eight rows (before I generate the random positions of the fish in the rank). Then one row could look like ~~~~~~~~~~><))'>~~~~~~~~~~~~~~~~...
[JAVA] I need help creating a method to calculate the Standard Deviation of a 2D Array. This is what I have so far: public double calcStdDev() { int total = 0; for(int i = 0; i < arr.length; i++){ total += arr[i][i]; } double mean = total / arr.length; return mean; } The numbers I'm using at just 1,2,3,4,5,6 and the standard deviation is coming out wrong. Can I have help fixing my...
JAVA ONLY 2D Arrays: You have been given a 10x10 array of integers, called Puzzle. You are to process the array, so that it verifies that each column’s elements are equal to the column’s index. That is, all elements in column 0 should be a 0, all elements in column 1 should be a 1, and so on. (Do not create the array, it is already created, no need to create main either)
In Java write the following array- processing methods into the same application, Lab13.java. Use the main method in this application to test your methods. 1) Write the void method, shiftLeft, which accepts an array of int and changes the elements of this array so that the index of each element is now less by one and the last element of the array is now zero. For example, if the parameter array is {7, 3, 2, 9, 5}, then when this...
Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...
in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...