'Printing the 2nd values in 2d Array

What change do I need to make in the following code

public void demo() {
    int[][] num = {{0, 30}, {5, 10}, {15, 20}};

    for(int i = 0; i < num.length; i++) {
     // System.out.println(num[i][0]); 
        for(int j = 0; j < num[i].length; j++) {
            System.out.println(num[j][i]);
        }
    }
}

So that I can get 30,10,20 ?
I want to find 0,5,15 which num[i][0] is doing. I am not sure what change to make just to get the 30,10,20

I do not want to use num[i][j] to get the pair values.



Solution 1:[1]

Try this:

public void demo() {
    int[][] num = {{0, 30}, {5, 10}, {15, 20}};

    for(int i=0;i<num.length;i++){
       System.out.println(num[i][1]); 
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yuri777