Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN JAVA Magic Squares. A magic square of order n is an arrangement of n ?n numbers, usually distinctintegers, in a square, such that

CODE IN JAVA

Magic Squares. A magic square of order n is an arrangement of n ?n numbers, usually distinctintegers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to thesame value. See the Wikipedia page for Magic Square at https://en.wikipedia.org/wiki/Magic_square.For this assignment, you will read data from a file and the format of the file will look like this.imageimage

Magic Squares. A magic square of order n is an arrangement of n n numbers, usually distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same value. See the Wikipedia page for Magic Square at https://en.wikipedia.org/wiki/Magic_square. For this assignment, you will read data from a file and the format of the file will look like this. Format of the input file 8 the size of the magic square 8,58, 59, 5,4,62,63,1 numbers surrounded by optional WS, separated by ',' 49, 15 , 14,52,53,11,10,56 41,23,22, 44, 45,19,18,48 32, 34, 35, 29, 28, 40,26,27,37,36,30,31,33 17,47,46,20,21,43,42,24 9,55,54,12,13, 51, 50, 16 64,2,3,61,60,6,7,57 38,39 ,25 Consider the following 7 x 7 magic square. All rows, columns, and diagonals in the magic square add up to 175. Notice the labeling of the rows and columns. Rows are represented as r#, columns are represented as c# and diagonals are represented as d1 and d2. c4 c5 c6 c7 d2 45 37 29 28 r1 3 44 36 35 27 19 r2 43 42 34 26 18 10 r3 dl cl c2 c3 r1 20 12 4 r2 11 r3 2 r4 49 41 33 25 17 r5 40 32 24 16 8 r6 31 23 15 14 r7 22 21 13 5 46 38 30 r7 9 1 r4 7 48 r5 47 39 r6 Your program will take a filename as an argument on the command line, read the data from the file and print whether the data forms a magic square or not. You may assume that the data in the files is specified correctly. When you extract the integers for a row, you should trim any surrounding whitespace before you convert it to an integer.

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Python Code that reads the data from the file and checks if it forms a magic square or not Heres the ... 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

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Programming questions

Question

What is a file? How can we read data from a file in Java?

Answered: 1 week ago

Question

Use implicit differentiation to find dy/dx. 6x 3 + 7y 3 = 13xy

Answered: 1 week ago