Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Magic Square: A n x n matrix that is filled with the numbers 1, 2, 3,.... n^2 is a magic square if the sum

Java Magic Square: A n x n matrix that is filled with the numbers 1, 2, 3,.... n^2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. I need to write an application that gets 16 values as user input, in any order. Store these values in an ArrayList. When the numbers are put into a square, this would be a 4x4 two-dimensional array.

image text in transcribed

Then test the following features to see if the numbers entered make a magic square:

1. Does each of the numbers 1 - 16 occur in the input? Note: I must perform this check from the ArrayList using the "contains" method. 2. Are the sums of the rows, columns, and diagonals equal to each other? If possible: when you store the number in the ArrayList, store it in a two-dimensional array too.

Heres a sample run (user input in bold): Enter the numbers 1 - 16 in any order: 12 13 2 7 6 3 16 9 15 10 5 4 1 8 11 14 - You found a magic square! - Heres another example: This time its not going to work: Enter the numbers 1 - 16 in any order: 2 3 7 10 9 16 4 5 12 8 1 15 14 11 13 6 - The numbers you have entered are not a magic square. And one more that wont work: Enter the numbers 1 - 16 in any order: 12 13 2 7 6 3 16 9 16 10 5 4 1 8 11 14 - The numbers you have entered are not a magic

Here's an example where n 4: 16 32 13 5 10 11 8 9 67 12 4 15 14 Let's look to see if it's a magic square. 34 34 8 34 12 34 34 34 10 11 6 15 14 7 4 34 34 34 34

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago