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 :: double number java 
Java :: java stream loop through list 
Java :: Java if...else Statement 
Java :: java interview questions 
Java :: regex java 
Java :: finding the ascii value of a character in java 
Java :: fragment call activity 
Java :: check if short int or long java 
Java :: Java 7. Converting List<List<Integer to int[][]: 
Java :: set web image to imageview android java 
Java :: java switch tutorial 
Java :: java insertion sort 
Java :: get image file path 
Java :: broadcast receiver for no interner android studio 
Java :: data structures in java 
Java :: meaning of instantiated in java 
Java :: positive numbers in array 
Java :: encapsulation in java 
Java :: enhanced for loop java 
Java :: spring login response data 
Java :: Split string into a string array 
Java :: package javafx.fxml does not exist 
Java :: for loop in java 
Java :: labeled statement in java ex 
Java :: Main method not found in class Ponga, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application 
Java :: Java program to print the character or a letter x using star 
Java :: location.href webview android studio 
Java :: one space diagonally in java 
Java :: layout focus from recycleview not from top in fragment inside nestedScrollview in android xml 
Java :: java GLIBC 2 34 missing 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =