Assume you are given an int variable named nElements and a 2-dimensional array that has been created and assigned to a2d. Write one or more statements that assign to nElements the total number of elements that could be stored in the entire 2-dimensional array.

LANGUAGE: JAVA

CHALLENGE:

Assume you are given an int variable named nElements and a 2-dimensional array that has been created and assigned to a2d. Write one or more statements that assign to nElements the total number of elements that could be stored in the entire 2-dimensional array.

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 ,

2 Comments

  1. dsafsgfgs on October 12, 2016 at 10:09 am

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

  2. fz on February 17, 2017 at 9:58 pm

    just change < for <

Leave a Comment

You must be logged in to post a comment.