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
within the data set hrd.temp, payrate is a numeric variable and hours is a character variable. what happens when the following p
Fantom [35]
  • SAS converts the PayRate value to a numeric value form; a message is written in the form of a log

  • SAS can be defined a comprehensive statistical software that provides a wide variety of analytical capabilities, data management, and visualization options

   

  • Compare between SAS and Python

Python is a high-level programming language, more object-oriented, and is known by all programmers.

In addition, python also includes a modern programming language.

Python is a programming language that has evolved from previous programming languages.

But in terms of learning, SAS is a programming language that is easier to follow compared to python.

These are the advantages and disadvantages of each programming language

Learn more about programming language here brainly.com/question/23959041

#SPJ1

6 0
2 years ago
Suppose the daytime processing load consists of 65% CPU activity and 35% disk activity. Your customers are complaining that the
bekas [8.4K]

Answer:

The answer to this question can be described as follows:

Explanation:

Given data:

Performance of the CPU:  

The Fastest Factor Fraction of Work:

f_1=65 \% \\\\=\frac{65}{100} \\\\ =0.65

Current Feature Speedup:

K_1= 1.5

CPU upgrade=6000

Disk activity:

The quickest part is the proportion of the work performed:

Current Feature Speedup:

k_2=3

Disk upgrade=8000

System speedup formula:

s=\frac{1}{(1-f)+(\frac{f}{k})}

Finding the CPU activity and disk activity by above formula:

CPU activity:

S_{CPU}=\frac{1}{(1-f_1)+(\frac{f_1}{k_1})} \\\\=\frac{1}{(1-0.65)+(\frac{0.65}{1.5})} \\\\=1.276 \%  ...\rightarrow (1) \\

Disk activity:

S_{DISK} = (\frac{1}{(1-f_2)+\frac{f_2}{k_2}}) \\\\ S_{DISK} = (\frac{1}{(1-0.35)+\frac{0.35}{3}}) \\\\ = -0.5\% .... \rightarrow (2)

CPU:

Formula for CPU upgrade:

= \frac{CPU \ upgrade}{S_{CPU}}\\\\= \frac{\$ 6,000}{1.276}\\\\= 4702.19....(3)

DISK:

Formula for DISK upgrade:

=\frac{Disk upgrade} {S_{DISK}}\\\\= \frac{\$ 8000}{-0.5 \% }\\\\= - 16000....(4)

equation (3) and (4),

Thus, for the least money the CPU alternative is the best performance upgrade.

b)

From (3) and (4) result,

The disc choice is therefore the best choice for a quicker system if you ever don't care about the cost.

c)

The break-event point for the upgrades:

=4702.19 x-0.5

= -2351.095

From (2) and (3))

Therefore, when you pay the sum for disc upgrades, all is equal $ -2351.095

4 0
3 years ago
When creating a documentary, what is not an appropriate source for footage?
Lorico [155]
The answer to this is similar documentaries on youtube!! Hope i helped
3 0
3 years ago
Assuming that a valid price should be between 30 and 50, does the following code snippet test this condition correctly?final int
san4es73 [151]

Answer

A) This code snippet ensures that the price value is between 30 and 50

Explanation:

The code snippet given ensures that the acceptable price values lies in the range of 30 and 50 inclusive of the lower and upper bound values. This condition is enforced with the the if...else if... else statements.

The first if statement;

if (price < MIN_PRICE){

           System.out.println("Error: The price is too low.");

}  checks if user inputted price is less that the MIN_PRICE which is 30 and displays the error message.

The second, an else if statement;

else if (price > MAX_PRICE) {

           System.out.println("Error: The price is too high.");

       } This checks if the user inputted price is above the MAX_PRICE which is 50 and displays the error message.

finally the else statement; else{ System.out.println("The price entered is in the valid price range.");

       } Prints the message confirming a valid price.

3 0
3 years ago
A key requirement for the process of testing hypotheses in the scientific method is Group of answer choices experimenter bias. c
Naily [24]

Answer:

Data Analysis

Explanation:

  • Data Analysis is the process by which statistical logical methods are systematically applied to classify,explain, present, assess and evaluate data.
  • This manipulation of data is done in order to retrieve some useful information from the data.
  • This useful information can help in testing hypothesis, drawing conclusions, making decisions, and making inferences or predictions on the basis of current or previous data.
  • There are some phases of data passes through like data collection in which the data is collected like questionnaires, surveys etc. data cleansing in which duplicate or incorrect data is removed.
  • Data Analysis interprets, and draw conclusions based on the certain requirements and goals.
  • Data Analysis helps further in other phases of data like data interpretation and presentation( visualization).
  • Many tools and software are available for data analysis such as MS Excel, R Programming etc.
5 0
3 years ago
Other questions:
  • Print "Censored' if userlnput contains the word "darn, else print userlnput. End with newline. Ex: If userinput is "That darn ca
    11·1 answer
  • HURRYYY A friend of yours has E-mailed their English paper to you so that you can proofread it. Explain the tools you would use
    15·1 answer
  • How many total numbers can be represented with an 8-bit binary (base-2) system?
    9·1 answer
  • The way a program is proceed is know as control flow and are :Sequence(one line after the other), Decision-making(either this or
    8·1 answer
  • With the range E2:E30 selected, create a new conditional formatting rule that uses a formula to apply yellow fill and bold font
    10·1 answer
  • Create a program which will input data into a pipe one character at a time. Count the number of characters as they are written i
    9·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·2 answers
  • 1. What are you going to do if someone ask for your personal information online?​
    12·2 answers
  • I need help. So basically the internet on my computer keeps turning off and on at random times. And when I try to reconnect it d
    15·2 answers
  • A cell's address, its position in the workbook, is referred to as a ________________ when it is used in a formula.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!