Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please answer in java and add comments. please answer as soon as possible . thank you so much Question 1: Magic Matrix A magic square
please answer in java and add comments. please answer as soon as possible . thank you so much
Question 1: Magic Matrix A magic square is an n x n matrix that has the following 2 properties: 1) It is filled with the numbers 1,2,3,....., n?, and each number occurs once and only once. 2) The sum of the elements in each row, in each column, and in the two diagonals is the same value. An example of magic square is as follows. 6 7 2 1 8 5 3 9 4. You are asked to write a Java code that can randomly generate one magic square. Your code will randomly generate a 3x3 matrix that satisfies 1) and then check if the matrix satisfies 2); If not, the Java code will continue generating another random matrix that satisfies 1) until a generated matrix that satisfies 2). Sample outputs could be as follows: Sample 1: The randomly generated matrix is: 4 3 8 9 5 1 2. 7 6 Sample 1: The randomly generated matrix is: 4 3 8 9 5 1 2 7 6. Sample 2: I The randomly generated matrix is: 4 9 2 3 5 7 8 1 6Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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