CODE IN JAVA Magic Squares. A magic square of order n is an arrangement of n ?n
Fantastic news! We've Found the answer you've been seeking!
Question:
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.
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Python Code that reads the data from the file and checks if it forms a magic square or not Heres the ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a program that will read data from the file "p6.txt". The file (that you will create) always contains 15 test scores (whole numbers between 0 and 100). The test scores are scores for 5 students...
-
What is a file? How can we read data from a file in Java?
-
The magic square is an arrangement of numbers in a square grid in such a way that the sum of the numbers in each row, and in each column, and in each diagonal is the same. MATLAB has a built-in...
-
Use implicit differentiation to find dy/dx. 6x 3 + 7y 3 = 13xy
-
How do an organizations resources and capabilities result in a competitive advantage?
-
What factors might explain why bullying persists? How do workplace bullies get away with it?
-
True or False: The following annual cash flows in years 1 thru 7, respectively, have a single real positive-valued root: \(-\$ 100,+\$ 15,-\$ 25,+\$ 75,-\$ 10,+\$ 50\), \(+\$ 50\).
-
As of December 31, 2016, Moss Company had total cash of $195,000, notes payable of $90,500, and common stock of $84,500. During 2017, Moss earned $42,000 of cash revenue, paid $24,000 for cash...
-
Ruler Formula Bar Normal Page Break Page Custom Preview Layout Views Gridlines Headings Zoom 100% Zoom To Selection Window Macros Workbook Views Show Zoom Macros A A1 V A B D E F G H 4 Assume That...
-
On August 31, Sunland Marine had an inventory of 21 boats at a cost of $2,100 each. Sunland does not expect any returns from sales of boats. The company uses a perpetual inventory system. During...
-
In Mohsin Hamids Exit West, discuss the tension between the traditional and the progressive. Secondly, there are particular challenges/difficulties of the immigrant experience both in legal and...
-
. Calculate the total resistance of a circuit where a fan (2 ohms) and 4 lights (1 ohm each) are all connected in parallel. O 6.00 3.00 0.150 0.22 0
-
If the hub gear and the ring gear R have angular velocities @ (rad/s) and WR (rad/s), respectively, determine the angular velocity ws (rad/s) of the spur gear S? 1 a. w = (-5w +3wH) 2 1 b. == (5WR +...
-
-0 Compute det B, where B = 01 1 12 2 1
-
The monochromatic emissivity of a diffuse-surface at 1600 K varies with wavelength in the following manner : = 0.4 for 0
-
Fig. 4.45 shows a one-arm device caliper and a three-arm bow-spring device caliper obtained in the same borehole in- terval. Explain the disagreement between the two logs in both the thick and thin...
-
An exponential function f(x) = ab' passes through the points (0, 11000) and (3, 11). What are the values of a and b? a= b
-
If the annual fixed costs are 54,000 dinars, the occupation expense represents 20%, the contribution margin is 25%, and the unit selling price is 40 dinars. Required: Calculate the closing point of...
-
A symmetric (5 x 5) Pascal matrix is displayed on the right. Write a MATLAB program that creates an n x n symmetric Pascal matrix. Use the program to create 4 x 4 and 7 x 7 Pascal matrices 1553| 15...
-
Newton's law of cooling gives the temperature T(t) of an object at time tin terms of T0, its temperature at t = 0, and Ts, the temperature of the surroundings. 33 T(t) = T3 + (T0 - T3)e-kt A police...
-
A list of 30 exam scores is: 31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43,98,36,87,22,61, 19,69,26,82,89,99, 71,59,49,64 Write a computer program that determines how many grades are...
-
The following are summaries of the cash book and bank accounts of J. Duncan who does not keep his books using the double entry system. You are required to: (a) Calculate the value of J. Duncan's...
-
Read the following and answer the questions below. On 31 December 2015 the bank column of C. Tench's cash book showed a debit balance of 1,500. The monthly bank statement written up to 31 December...
-
The bank columns in the cash book for June 2016 and the bank statement for that month for D. Hogan are as follows: You are required to: () Write the cash book up to date to take the above into...
Study smarter with the SolutionInn App