Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

making matrix in java

public static void main(String[] args) {

    // When instantiating an array, you give it sizes, not indices
    int[][] arr = new int[3][1];

    // These are all the valid index combinations for this array
    arr[0][0] = 3;
    arr[1][0] = 5;
    arr[2][0] = 6;

    int max = 1;

    // To use these variables outside of the loop, you need to 
    // declare them outside the loop.
    int x = 0;
    int y = 0;

    for (; x < arr.length; x++) {
        for (; y < arr[x].length; y++) {
            if (arr[x][y] > max) {
                max = arr[x][y];
                System.out.println(max);
            }
            System.out.println(arr[x][y]);
        }
    }

    // This print statement accesses x and y outside the loop
    System.out.println(arr[x][y]);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #making #matrix #java
ADD COMMENT
Topic
Name
2+5 =