0

What would be the last valid index for this array?

double[][] array = new double[11][17];
4
  • And you what do you think? Commented Nov 7, 2014 at 20:53
  • 1
    There are 2 separate indices; which do you mean? Commented Nov 7, 2014 at 20:54
  • 1
    @AfzaalAhmadZeeshan: 17th element of each of the 11 arrays... Commented Nov 7, 2014 at 20:54
  • This was a quiz question and i was just confused because it was multidimensional. I know that the last index of the row is 10 and 16 for the column i just wasn't sure if you put it like 10 and 16 or if i was supposed to combine them or something. Commented Nov 7, 2014 at 22:01

1 Answer 1

2

The answer is [10][16], let's see how in code.

public static void main(String[] args) {
    double[][] array = new double[11][17];
    for (int i = 0; i < array.length; i++) {
        for (int j = 0; j < array[i].length; j++) {
            System.out.printf("[%d][%d]%n", i, j);
        }
    }
}

And the last line of output is

[10][16]

Or, you could remember that array indexes start at 0 and the last element of an array is at the length of the array - 1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.