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]
2 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]2 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
The following loop is intended to print the numbers 1, 2, 3, 4, 5.
balu736 [363]

Answer:

range

Explanation:

range(num1, num2) returns the numbers from num1 up to but not including num2.

Example: range(1, 4) will return the numbers 1, 2, 3.

Hope this helps :)

8 0
2 years ago
What is ransomware<br>я​
Novosadov [1.4K]

Answer:

Ransomware is malicious software that infects your computer and displays messages demanding a fee to be paid in order for your system to work again. It has the ability to lock a computer screen or encrypt important, predetermined files with a password.

Explanation:

:)

5 0
2 years ago
Can someone let me join your kingdom if anybody knows this game and plays it as well. ​
Assoli18 [71]

Answer:

sure is called voxetas

Explanation:

7 0
2 years ago
Which of the following is opened when the Find command is clicked? Question 9 options: Navigation Pane Insert Hyperlink dialog b
Dima020 [189]

The element, from the following options, which is opened when the find command is clicked is the search pane.

What is find command?

Find command is the command which is used to find the list of files and their location.

Find command can be used in different manners-

  • To find the different files in a system.
  • Find command can find the files by their name, size, date or other information related to the required document.
  • This command can be modified with the requirement of the search.

The options for the given problem are-

  • Navigation Pane Insert- It is used to show the navigation pane in word or similar space.
  • Hyperlink dialog box-This open, when the insert hyperlink command is clicked.
  • Bookmark dialog box-This opens, when the bookmark command is clicked.
  • Search Pane- Search pane is opens, when the find commond is clicked.

Thus, the element, from the following options, which is opened when the find command is clicked is the search pane.

Learn more about the find command here:

brainly.com/question/25243683

4 0
2 years ago
What are 2 ways to access the vendor credit screen in quickbooks online?
kiruha [24]

Answer:

First by

Clicking

New Button (+) THEN click Vendor THEN click Credit

Secondly

Click Expenses Center then click New Transaction then finally click Vendor Credit

4 0
2 years ago
Other questions:
  • A(n) ____________________ stores copies of data or programs that are located on the hard drive and that might be needed soon in
    9·1 answer
  • The _____ is the area in Microsoft Excel where you can perform file commands such as Save, Open, and Print
    15·1 answer
  • Elise has just edited two photos of her cat and three different photos of her dog. She needs to save all five of these photos in
    5·2 answers
  • Which of the following is an example of a direct payment subsidy?
    12·1 answer
  • How many seconds are required to make a left turn and join traffic?​
    11·2 answers
  • In which of the following ways can using test-taking tips help you?
    7·1 answer
  • All health information available on the internet is valid. <br> a. true <br> b. false
    6·1 answer
  • How to turn off windows 10 without loosing sound?
    11·1 answer
  • PLEASE HELP I HAVE A TEST RIGHT NOW!!!
    13·1 answer
  • Which of the following is a type of input device?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!