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
Jed is the database administrator for a mid-sized computer component manufacturer. He is responsible for validating the data mod
svet-max [94.6K]

Answer:

Development task is the correct answer to the given question.

Explanation:

The database administrator is responsible for managing the database management system . The overall security of the database is depended on the database administrator.

The Development task include the following function  

  • Verification of the data model that is used by the database management system .
  • Check the user input it means validating the data.
  • Defining the overall requirement to create the model.
  • Providing backup when the data is loss .

So the Development task is the correct answer.

3 0
3 years ago
What is the difference between cd-r, cd-rw and cd-rom​
insens350 [35]

Answer:

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

Explanation:

          "difference between cd-r, cd-rw and cd-rom​"

CDs are also known as WORM discs,for "write once Read many".A re writable version based on excitable crystals and known as CD-RW was introduced in the mid 1990s because both CD-R and CD-RW recorders originally required a computer to operate  they had limited acceptance of use as computer software.

  A compact Disc Read only memory (CD-ROM) is a read only disc.A compact disc Re-writable (CD-RW) is an erasable disc that can be reused.The data  on a CD-RW disc can be erased and recorded over numerous times.CD-RW may not be readable outside of the drive it was created in.

cd-r :

          CD-R is a digital optical disc storage format.A CD-R disc is compact disc that can be written once and read arbitrarily many times.

          CD-R stand for" compact disc" Record-able .CD-R disc are blank CDs that can record data written by a CD burner.The word "record-able" is used because CD-R are often used to record audio,Which can be play back by most CD players.

cd-rw:

           CD-RW compact disc re-writable is a digital optical disc,storage format introduced in 1997.A CD-RW compact disc can be written read erased and re-written.

in this case of CD-RW the writing laser makes permanent marks in a layers of dye polymer in the disc.CD rewrite-able discs in a similar fashion,except that the change to the recording surface is revers able.

cd-rom:

         CD-Rom observation of compact disc read only memory type of computer memory in the form of compact disc that is read by optical means.A CD-ROM drive uses a low power laser been encoded in the form of tiny pits on a optical disk.The "ROM" part of the term means the data on the disc "read only memory" or cannot be altered or erased.

8 0
2 years ago
SOMEONE PLEASE HELP ME OUT !!!!!!
GrogVix [38]

Answer:

not completly sure but i believe its the one that says inform the coach of where the goalies weak area...

Explanation:

8 0
3 years ago
Nina aspires to be a digital media specialist. What should Nina be familiar with in order to pursue this career?
never [62]
D because they do more about software
6 0
3 years ago
Read 2 more answers
How are computers connected to one another?
sergeinik [125]

Answer:

They are connected through networks

Explanation:

N/A

7 0
3 years ago
Read 2 more answers
Other questions:
  • What helps companies and organizations to target masses of people, provide 24/7 services, and deliver better marketing in a chea
    10·1 answer
  • Tom Daniels, an employee of a telecommunications company, is developing software that would enable customers to activate value-a
    7·1 answer
  • Which option describes wearable technology?
    9·1 answer
  • In c#, how are parameters passed on?
    15·2 answers
  • Next, Kim decides to include a diagram of a frog’s life cycle in her presentation. She wants to use an image that is part of a p
    15·2 answers
  • Most search engines provide specific pages on which you can search for____ and
    14·2 answers
  • What is the purpose of the new window command
    6·1 answer
  • What output is generated by this for loop?
    6·1 answer
  • An animation of a person standing with their arms extended out to their sides. There are 3 dimensional boxes around the torso of
    5·1 answer
  • KELLY Connect
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!