Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java Question #1: calculate Even Sum (50 points): Please fill the function int calEvenSum (int n) to calculate the sum of all even numbers

in java

Question #1: calculate Even Sum (50 points): Please fill the function int calEvenSum (int n) to calculate the sum of all even numbers between 1 and n (including). ( Hint: Even number is evenly divisible by two.)

For example,

Input: n = 4 Return: 6 (Because 2 + 4 = 6) n = 3 Return: 2

Question #2: checkMagicSquare (50 points): Please write the function boolean checkMagicSquare (int [][]) is to check if the given square matrix is a magic square. (Note: For a square matrix, if the sum of all the elements on main diagonal and the sum of all elements on anti-diagonal are the same, this matrix is defined as a magic square.)

For example

Input: arr = {1, 4

2, 6}

Return: False (Because 1 + 6 2 + 4)

Input: arr = {1, 4, 4

2, 1, 5 3, 5, 6}

Return: True (Because 1 + 1 + 6 = 4 + 1 + 3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions