From 8b25c450f1523b279b9c4225386f406aa43e20b7 Mon Sep 17 00:00:00 2001 From: jimmysingla0399 <116092607+jimmysingla0399@users.noreply.github.com> Date: Wed, 19 Oct 2022 13:16:53 +0530 Subject: [PATCH] Create jaggedarray.java --- jaggedarray.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 jaggedarray.java diff --git a/jaggedarray.java b/jaggedarray.java new file mode 100644 index 0000000..14be846 --- /dev/null +++ b/jaggedarray.java @@ -0,0 +1,29 @@ +class Main { + public static void main(String[] args) + { + // Declaring 2-D array with 2 rows + int arr[][] = new int[2][]; + + // Making the above array Jagged + + // First row has 3 columns + arr[0] = new int[3]; + + // Second row has 2 columns + arr[1] = new int[2]; + + // 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(); + } + } +}