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
1. Railroad tracks present no problems for a motorcyclist.
Yuki888 [10]

Answer: 1 is A

2 is D

Explanation:

3 0
2 years ago
Indentation is useful to make the document easier to read. To increase the indentation of the paragraph, you press the increase
jeka94

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

The correct answer is Home.

Indentation is useful to make the document easier to read. To increase the indentation of the paragraph, you press the increase indentation in the   <u>Home</u> tab.

you can increase/ decrease indentation in Home tab under the Paragraph groups of command.

Othe options are not correct because:

View tab has settings related to how the document looks like. Insert tab has settings related to the insertion of image, shape, pages, tables, illustration, and links, etc into a document. The review tab allows you to review the document with different available settings.

4 0
3 years ago
Which type of memory is used as the working storage space of the computer?
natta225 [31]
Internal memory is used as the working storage space of the computer
4 0
3 years ago
Cuantos días tiene un año
Arte-miy333 [17]

Answer: 365 dias

Explanation:

4 0
2 years ago
Your license can be revoked if you’re found guilty or not stopping to give when the vehicle you were driving is involved in a cr
BigorU [14]
Causing a death or personal injury
5 0
2 years ago
Other questions:
  • This is a list of commands that tell your computer what to do. A icon B FAT C GUI D menu
    5·2 answers
  • which tag does not display the text in the browser window and makes the sources code mode readable ?​
    6·1 answer
  • A collision volume is called ____
    7·1 answer
  • Vaporization is the process in which liquid is sufficiently cooled to change states of matter from a liquid to a vapor true or f
    8·1 answer
  • Which of the following is designed to help an organization continue to operate during and after a disruption?
    12·1 answer
  • Point out the wrong statement:
    7·1 answer
  • Will mark Brainliest!! What is the best memory to use on a computer? Why?
    9·1 answer
  • The director of security at an organization has begun reviewing vulnerability scanner results and notices a wide range of vulner
    11·1 answer
  • A ……………………………is used to verify the identity of a website and is issued to the owner of the website by an independent and recogni
    7·2 answers
  • the application you attempted to authenticate to is not authorized to use cas. contact your cas administrator to learn how you m
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!