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
When do I use while loops
Marat540 [252]

Answer:

When you dont know how long the loop is going to run for

Explanation:

7 0
3 years ago
The "origin" of the cartesian plane in math is the point where x and y are both zero. Given a variable, origin of type Point-- a
Sergeeva-Olga [200]

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. struct Point{
  4.    double x;
  5.    double y;
  6. };
  7. int main()
  8. {
  9.    Point origin;
  10.    origin.x = 0;
  11.    origin.y = 0;
  12.    return 0;
  13. }

Explanation:

The solution code is written in C++.

Firstly, we create a data structure Point with two fields, x and y (Line 5 -8).

In the main program, declare an origin object with Point type (Line 12).

Set the x and y fields of origin object to zero using dot syntax (Line 13-14).

3 0
4 years ago
Extended essay on globalization not less than 200​
Serggg [28]

Answer:

First of all, people have been trading goods since civilization began. In the 1st century BC, there was the transportation of goods from China to Europe. The goods transportation took place along the Silk Road. The Silk Road route was very long in distance. This was a remarkable development in the history of Globalization. This is because, for the first time ever, goods were sold across continents.

Globalization kept on growing gradually since 1st BC. Another significant development took place in the 7th century AD. This was the time when the religion of Islam spread. Most noteworthy, Arab merchants led to a rapid expansion of international trade. By the 9th century, there was the domination of Muslim traders on international trade. Furthermore, the focus of trade at this time was spices.

True Global trade began in the Age of Discovery in the 15th century. The Eastern and Western continents were connected by European merchants. There was the discovery of America in this period. Consequently, global trade reached America from Europe.

From the 19th century, there was a domination of Great Britain all over the world. There was a rapid spread of international trade. The British developed powerful ships and trains. Consequently, the speed of transportation greatly increased. The rate of production of goods also significantly increased. Communication also got faster which was better for Global trade.

Finally, in 20th and 21st -Century Globalization took its ultimate form. Above all, the development of technology and the internet took place. This was a massive aid for Globalization. Hence, E-commerce plays a huge role in Globalization.

5 0
3 years ago
A client with severe diverticulitis is admitted to the hospital for bowel surgery, and a colostomy is performed. Which observati
trasher [3.6K]

The stoma should be beefy red.

Explanation:

Diverticulitis is an inflammatory disease of the colon. In case of severe diverticulitis, the part of the inflamed colon is cut through a small hole and stool is made to exit out through the stomach and collected in a colostomy bag.

The stoma is the cut end of the colon where the hole is made. This end should be monitored after colostomy and look for any excessive bleeding or for signs of infection.

Normally a healthy looking stoma is beefy red in color resembling the color inside the mouth.

The LPN/LVN should first observe the color of the stoma to check whether it is normal.

3 0
3 years ago
Write a program that allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times
s344n2d4d5 [400]

Answer:

Here is a Python program that allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times. The program uses a while loop to continuously prompt the user for input until they enter a valid number of dice and rolls. It also uses a for loop to simulate the dice rolls and a random module to generate random numbers for the dice rolls.

import random

while True:

   # Prompt the user for the number of dice to roll

   num_dice = int(input("Enter the number of dice to roll (1-100): "))

   if num_dice < 1 or num_dice > 100:

       continue

   # Prompt the user for the number of rolls to perform

   num_rolls = int(input("Enter the number of rolls to perform (1-1000): "))

   if num_rolls < 1 or num_rolls > 1000:

       continue

   # Simulate the dice rolls and print the results

   for i in range(num_rolls):

       roll = 0

       for j in range(num_dice):

           roll += random.randint(1, 6)

       print(f"Roll {i+1}: {roll}")

   # Ask the user if they want to roll again

   again = input("Roll again? (Y/N): ").upper()

   if again != "Y":

       break

Explanation:

In this program, we first import the random module to use its randint function to generate random numbers for the dice rolls. We then enter a while loop that will continuously prompt the user for input until they enter a valid number of dice and rolls. Within the while loop, we prompt the user for the number of dice to roll and the number of rolls to perform. If the user enters an invalid number of dice or rolls, we continue back to the beginning of the loop and prompt the user again.

Once the user has entered a valid number of dice and rolls, we use a for loop to simulate the dice rolls. For each roll, we use another for loop to roll the specified number of dice and add up the results. We then print the total for each roll. After all of the rolls have been performed, we ask the user if they want to roll again. If they enter "Y", we continue back to the beginning of the while loop to prompt them for new input. If they enter anything else, we break out of the while loop and end the program.

Overall, this program allows a user to choose to roll between 1 and 100 dice between 1 and 1000 times, and simulates the dice rolls using random numbers and loops.

8 0
1 year ago
Other questions:
  • What is intergrated circuit ic​
    10·1 answer
  • To mark all modifications made to the document, activate the
    10·2 answers
  • To move to the beginning of the line with the keyboard, press the _______ key(s).
    6·1 answer
  • What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
    8·1 answer
  • Which of the following are TRUE? A function can call another function. As long as the function is defined anywhere in your progr
    14·1 answer
  • Ive already tried "word" and "star"
    12·1 answer
  • Keyshia wants to add movement to her PowerPoint presentation. Which tab should she use to complete this task
    15·2 answers
  • PROGRAM LANGUAGE C
    5·1 answer
  • Can you plz type down a word.
    11·2 answers
  • How do you answer other peoples questions on Brainly? I know how to ask them but not answer hmm...
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!