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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started