Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

jagged array java

int[][] numbers = new int[7][];

// row 0 gets 5 columns
numbers[0] = new int[5];
// row 1 gets 11 columns
numbers[1] = new int[11];
// etc...
Comment

java 2d jagged array example

// Java program to demonstrate 2-D jagged
// array such that first row has 1 element, second
// row has two elements and so on.
class Main {
    public static void main(String[] args)
    {
        int r = 5;
 
        // Declaring 2-D array with 5 rows
        int arr[][] = new int[r][];
 
        // Creating a 2D array such that first row
        // has 1 element, second row has two
        // elements and so on.
        for (int i = 0; i < arr.length; i++)
            arr[i] = new int[i + 1];
 
        // Initializing array
        int count = 0;
        for (int i = 0; i < arr.length; i++)
            for (int j = 0; j < arr[i].length; j++)
                arr[i][j] = count++;
 
        // Displaying the values of 2D Jagged array
        System.out.println("Contents of 2D Jagged Array");
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++)
                System.out.print(arr[i][j] + " ");
            System.out.println();
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to take an element out of an array at a certain index in java 
Java :: java number 
Java :: java string to path 
Java :: write json string to file in java 
Java :: map string list string in java 
Java :: slice array java 
Java :: java stack using linked list 
Java :: javadoc link to class 
Java :: java gui 
Java :: java sout two dimensional array 
Java :: creating array java 
Java :: java create new thread 
Java :: java 2d array for each 
Java :: how to create an array list of ints in java 
Java :: get random word from list java 
Java :: java try catch 
Java :: data java 
Java :: java logger error 
Java :: turn java code to .exe 
Java :: return empty array from method 
Java :: Fast Lookup of Java 
Java :: SendKeys issues with numbers(Int) 
Java :: insert data into list java 
Java :: java double format 
Java :: kotlin variable in string 
Java :: count vowels in java 
Java :: what is use of static block in java 
Java :: set java home sdk macbook 
Java :: range in java 
Java :: retrofit implementation 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =