Java adding a number to array element

So I got 2 methods. One which will create a multi level array and pass that and a number to my other method. My other method will then add the number to each element in the array and then my first method will print the modified array. This is my code:

Method 1:

enter code her public void exercise18d1() {
    double[][] array1 = {{2.3,6.1},{3.3,8.6},{5.4,5.2}};
    double[][] array2 = {{2.3,6.1,7.0,3.5},{3.3,8.6},{5.4,5.5,5.2}};
    increase(array1, 1.2); //plus 1 plus 2
    increase(array2, -1);//minus 1
    print(array1,5,1);
    System.out.println();
    print(array2,5,1);
}

Method 2 which modifies the array.

  public void increase(double[][] arr, double nbr) {
    for(int i = 0;i <arr.length;i++){
        arr[i][i] += nbr;

    }

The problem is with the second method. I don't have any clue on how to fix this. arr[i][i]+=nbr should mean that the element on i position should be added with nbr. So to clarify the result should be:

   3,5  7,3 
   4,5  9,8 
   6,6  6,4

   1,3  5,1  6,0  2,5
   2,3  7,6
   4,4  4,5  4,2
Jon Skeet
people
quotationmark

My other method will then add the number to each element in the array

That's not what it's doing at the moment. It's modifying each "diagonal" element. Imagine that you have a 5 x 10 array... you're currently only modifying 5 entries. You want nested loops - something like:

public void increaseAll(double[][] array, double amount) {
    for (double[] subArray : array) {
        for (int i = 0; i < subArray.length; i++) {
            subArray[i] += amount;
        }
    }
}

Or just using for loops:

public void increaseAll(double[][] array, double amount) {
    for (int i = 0; i < array.length; i++) {             
        for (int j = 0; i < array[i].length; j++) {
            array[i][j] += amount;
        }
    }
}

people

See more on this question at Stackoverflow