Assignment No.10

  1. (Adapted from Textbook Chapter 7 Exercise 20) Write a method called isMagicSquare that accepts a two-dimensional array of integers as a parameter and returns true if it is a magic square. A square matrix is a magic square if all of its row sums and column sums are equal to each other. For example, [[2, 7, 6], [9, 5, 1] [4, 3, 8]] is a magic square.

  2. Write a method called variety that returns the number of distinct values appearing in an array of Strings. For example, if an array called slist contains the values [“abc”, “def”, “abc”, “xyz”, “def”] variety(slist) should return 3.

Go back to the assignment list page.