Assume you are given a boolean variable named isRectangular and a 2-dimensional array that has has been created and assigned to a2d. Write some statements that assign true to isRectangular if the entire 2-dimensional array is rectangular, meaning every row has the same number of elements as every other row.

LANGUAGE: JAVA

CHALLENGE:

Assume you are given a boolean variable named isRectangular and a 2-dimensional array that has has been created and assigned to a2d. Write some statements that assign true to isRectangular if the entire 2-dimensional array is rectangular, meaning every row has the same number of elements as every other row.

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

1 Comment

  1. AL on November 9, 2016 at 11:53 pm

    isRectangular = true;
    for (int i = 1; i < a2d.length && isRectangular; i++)
    if (a2d[i].length != a2d[0].length)
    isRectangular = false;

Leave a Comment

You must be logged in to post a comment.