Question: I wrote the java, but I can't solve the math problem that java will print the center of the matrix. need to solve: static void

I wrote the java, but I can't solve the math problem that java will print the center of the matrix.

need to solve:

static void printMatrixCenter(int [][] matrix):

prints the square matrix at the center of the given matrix, that is all the numbers of the given matrix except those on the first and last row, and first and last column.

Example 1.

Input:

Please enter an integer between 2 and 10: 4

Please enter a 4 by 4 matrix:

5 7 7 8

12 0 -5 15

3 12 9 10

7 3 8 7

Output:

The center of the matrix is :

0 -5

12 9

My JAVA______________________________________________________________________________________________________________________________________________

package squrarematrixcenter;

import java.util.Scanner;

public class SqurareMatrixCenter { static int n; public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter an integer between 2 and 10: "); n = input.nextInt(); while (n < 2 || n > 10) { System.out.println("Please enter an integer between 2 and 10: "); n = input.nextInt(); } int[][] myMatrix = new int[n][n]; System.out.print("Enter a " + n + " by " + n + " matrix row by rows: "); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { myMatrix[i][j] = input.nextInt(); } } printMatrixCenter(myMatrix); } public static void printMatrixCenter(int[][] matrix)

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!