1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dvinal [7]
3 years ago
7

Write a class called MagicSquare, which contains a single method called check that accepts a two-dimensional array as an argumen

t, and determines whether the array is a Magic Square. Write a class called MagicSquareDemo, which demonstrates the above class/method.
Computers and Technology
1 answer:
ira [324]3 years ago
5 0

Answer:

public class MagicSquare {

   public static void main(String[] args) {

       int[][] square = {

               { 8, 11, 14, 1},

               {13, 2, 7,12},

               { 3, 16, 9, 6},

               {10, 5, 4, 15}

       };

       System.out.printf("The square %s a magic square. %n",

               (isMagicSquare(square) ? "is" : "is not"));

   }

   public static boolean isMagicSquare(int[][] square) {

       if(square.length != square[0].length) {

           return false;

       }

       int sum = 0;

       for(int i = 0; i < square[0].length; ++i) {

           sum += square[0][i];

       }

       int d1 = 0, d2 = 0;

       for(int i = 0; i < square.length; ++i) {

           int row_sum = 0;

           int col_sum = 0;

           for(int j = 0; j < square[0].length; ++j) {

               if(i == j) {

                   d1 += square[i][j];

               }

               if(j == square.length-i-1) {

                   d2 += square[i][j];

               }

               row_sum += square[i][j];

               col_sum += square[j][i];

           }

           if(row_sum != sum || col_sum != sum) {

               return false;

           }

       }

       return d1 == sum && d2 == sum;

   }

}

You might be interested in
Jamie is not sure a new medication will work because it has not had a large test group. Is Jamie being creative?
Mumz [18]
No, they're being skeptical.
4 0
3 years ago
Read 2 more answers
What is the appropriate guidelines to create and manage files
Maurinko [17]

Answer:

1. Do not copyright

2. Nothing illegal

3.Do not put personal info

Explanation:

3 0
3 years ago
What is an idea for novel food production technologies or systems that require minimal resources and produce minimal waste, whil
Luden [163]

Answer:

Dehydrated food that is vacuumed sealed.

Explanation:

Dehydrated food is not hard to make and holds the nutritious values needed for a human to survive. Dehydrated food can last up to 1-2 years if vacuumed sealed.

7 0
2 years ago
Read 2 more answers
"the ________ attribute of the anchor tag can cause the new web page to open in its own browser window."
zheka24 [161]
Target





-------------------------------
8 0
3 years ago
How the python programming interesting for non programmers?
aleksandrvk [35]

Answer:

The python programming language is interesting for non-programmers as it is easy to learn the syntax.  It has extensive libraries that can support every action of the non-programmer and programmer.

Explanation:

Python as a programming language has proved to be the easiest to learn and use.  It is also powerful and versatile, making it the best choice for all beginners and experts.  The readability of the Python language also makes it a great first programming language to learn.  It enables one to think like a programmer and not waste time over any confusing syntax.  Another great advantage possessed by the Python language is that it is easy to download and install for use.

6 0
2 years ago
Other questions:
  • A server-side extension ________________. provides its services to the web server in a way that is totally transparent to the cl
    13·1 answer
  • What is a computer??????????????????????????????????????????????????????????
    12·2 answers
  • You can apply several different worksheet themes from which tab?
    10·2 answers
  • Does anyone know what anotmy means​
    8·2 answers
  • The main purpose of a service panel in a house is to
    11·1 answer
  • What is the reason that friction is present in surface to surface contact?
    5·1 answer
  • During project management, who executes tasks and produces the deliverables as stated in the project plan and as directed by the
    9·1 answer
  • Subscribe to my you tube channel to get all your questions answered
    8·1 answer
  • What do you think that the next version of IR (IR 5.0) will bring if it was discovered in near future? (hint:- advance IR 4.0 fe
    8·1 answer
  • Explain with examples the roles of system software and application software?<br>​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!