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
An app builder has created a report for sales people to view records from the custom object, some users have complained that the
a_sh-v [17]

Answer:

Check sharing rules

Check organization-wide defaults

Check the user s profile for object settings

Explanation:

There is a need for some people to see the total transparency of the records that are meant to be shared with a select group of people. There are certain things that can be done for this. The first one is that the sharing rules should be checked. To whom are the details shared with. The next one is the filters that are used.

These can be reported and changed accordingly. Lastly, the whole organization’s defaults can be checked. This is something that can be done when the previous methods that were done did not work that well. Once some changes are done, the people can check if they already work and if the records can be viewed.

6 0
4 years ago
I came here for a answer so why did i get a pep talk
Llana [10]

Answer:

idek my guy

Explanation:

6 0
3 years ago
Read 2 more answers
What does the do not disturb button do on the iphone?
Andreas93 [3]
It wont give you texting or calling notifications
4 0
4 years ago
A computer's hard disk drive holds 8 x 10^10 bytes of information. If Jill buys an extra memory stick that holds 5.1 X 10^8 byte
denis-greek [22]

Answer:

The computer will store 8.05 *10^10 bytes of information.

Explanation:

This is the same as saying that the computer will now have 80.51 Gigabytes ( 1gb = 1.000.000.000 bytes) of storage. In this case, the number is represented in its decimal form, and the previous one is displayed in Scientific Notation.

8 0
3 years ago
Which event occurred in the 1990s?
Amanda [17]

Answer:

C) Sun Microsystems released Java.

Explanation:

Sun Microsystems released in May 1995.  Of course, Sun Microsystems was then bought by Oracle.  Today, it's said that Java is the most commonly used programming language and that over over 3 billion devices use it.

It was created by James Goesling, a Canadian from Calgary, Alberta.

Let's check the other dates to be sure:

A) Niklaus Wirth developed Pascal. : 1970

B) The Department of Defense released Ada.  1980

D) Bjarne Stroustrup developed C++.: 1985

5 0
3 years ago
Other questions:
  • Security testing attempts to verify that protection mechanisms built into a system protect it from improper penetration.
    9·1 answer
  • Explain why living things store energy in lipids instead of in carbohydrates
    5·1 answer
  • Match the Windows installation technique to its description.
    15·1 answer
  • Which is the output of the formula =NOT(12+12=24) ?
    7·1 answer
  • What are 2 main differences betweenarrays andstructs?
    7·1 answer
  • ____ is an easy way to invitation through a web page​
    13·1 answer
  • Which kind of image is indispensable and needs added text to go with it?
    13·1 answer
  • My chrome book computer clock is an hour off how do I fix that
    14·1 answer
  • 4. In computers, an integer can be represented by more than 8-bit, what is the largest positive integer that
    9·1 answer
  • compare the two methods of creating table in ms access ( Datasheet view and Design view) which one wouldyou prefer to use to rec
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!