you will write a Java program that generates an n × n matrix filled with elements from 1 to n 2 in spiral order, where n is a given input size.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In this assignment, you will write a Java program that generates an n × n matrix filled with elements from 1 to n 2 in spiral order, where n is a given input size. A spiral matrix is a matrix of the type which puts numbers in a circular fashion rather than in row-major or column-major fashion. The elements stored in the spiral matrix can be in clockwise (See Figure 1), or in counter clockwise (See Figure 2). Figure 1: A clockwise values Figure 2: A counter-clockwise values You may name your Java file name as MatrixApp.java, and write two methods that generate two versions of spiral matrices given any input matrix size n, and print out secondary diagonal values (See Figures 3-4 red-colored values). The detailed descriptions of two methods are as follows: 1 Figure 3: A clockwise spiral matrix with red-colored values should be printed /* * @n: input matrix size * * print out the secondary diagonal values from top to down * e.g., for n = 6, you will print 6, 24, 34, 36, 30, 16 */ public static void clockwise_spiralmatrix_diagonals(int n)) { // The Big Picture: // 1) create a matrix (mat) with n by n // 2) now fill the elements as follows, starting with cell mat[0][0]: // a) move right, fill up the first row // b) move down, fill up the last column // c) move left, fill up the last row // d) move up, fill up the first column // 3) repeat the process but moving insider cells now, // until all elements have been filled // Question: how do you know you complete this process? // Answer: all n x n numbers have been used // now you can print out the secondary diagonal values } 2 Figure 4: A counter clockwise spiral matrix with red-colored values should be printed /* * @n: input matrix size * * print out the secondary diagonal values from top to down * e.g., for n = 6, you will print 16, 30, 36, 34, 24, 6 */ public static void clockwise_spiralmatrix_diagonals(int n)) { // The Big Picture: // 1) create a matrix (mat) with n by n // 2) now fill the elements as follows, starting with cell mat[0][0]: // a) move down, fill up the first column // b) move right, fill up the last row // c) move up, fill up the last column // d) move left, fill up the first row // 3) repeat the process but moving insider cells now, // until all elements have been filled // Question: how do you know you complete this process? // Answer: all n x n numbers have been used // now you can print out the secondary diagonal values } 3 In your main() method, you will test two methods for input matrix sizes of 6, 7, 8, 9, and 10. Your outputs should labeled clearly like the followings. clockwise (n=6): 6, 24, 34, 36, 30, 16 counterclockwise (n=6): 16, 30, 36, 34, 24, 6 ...

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Randomized Select Algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education