Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an application named SquareMatrixCenter whose main method askes the user to enter an integer number n (between 2 and 10), and an n by

Create an application named SquareMatrixCenter whose main method askes the user to enter an integer number n (between 2 and 10), and an n by n integer matrix then passes the matrix with the values entered by the user to the following method:

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.

Use the Scanner class to read the users input.

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

I did create java code to find center of the matrix, but I am struggle to make java for the output.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> package squrarematrixcenter; import java.util.Scanner; import java.util.*; public class SqurareMatrixCenter { public static void printMatrixCenter(int[][] matrix) { int n = matrix.length; System.out.println("The center of the matrix is: "); for (int i = 1; i < n - 1; i++) { for (int j = 1; j < n - 1; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(""); } }

public static void main(String[] args) { int n; Scanner input = new Scanner(System.in); System.out.println("Please enter an integer between 2 and 10: "); n = input.nextInt(); int[][] myMatrix; while (n < 2 || n > 10) { System.out.println("Please enter an integer between 2 and 10: "); n = input.nextInt(); } 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(); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions