Ask Question
2 September, 15:12

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.

+1
Answers (1)
  1. 2 September, 15:21
    0
    nElements = 0;

    for (int i = 0; i < a2d. length; i++)

    nElements + = a2d[i]. length;

    isRectangular = true;

    for (int i = 1; i < a2d. length && isRectangular; i++)

    if (a2d[i]. length! = a2d[0]. length)

    isRectangular = false;

    Step-by-step explanation:

    2 dimensional array is created and initialize element with 0. and the taking loop for 2 dimensional array. such as

    n Elements = 0;

    for (int i = 0; i < a2d. length; i++)

    n Elements + = a2d[i]. length;

    A boolean variable isRectangular and 2 dimensional array has been created if rectangle is true the take a2d. length and isRectangular less than i and intiliaze i with 1 then increment the i. It will give true value.

    If rectangular is false then apply if statement and see if a2d[i] is not equal to a2d[0]

    if (a2d[i]. length! = a2d[0]. length)

    isRectangular = false;
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume you are given a boolean variable named isRectangular and a 2-dimensional array that has has been created and assigned to a2d. Write ...” in 📗 Mathematics if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers