1+ import java .util .*;
2+ public class Ragged_Array {
3+
4+ public static void main (String []args ) {
5+ Scanner sc =new Scanner (System .in );
6+ System .out .print ("Enter the Number of Rows in the Ragged array: " );
7+ int row =sc .nextInt ();
8+ //Asking for the number of rows
9+ int [][]arr =new int [row ][];//u have to mention row number
10+ /*
11+ In case of Ragged Array or Zagged Array the number of elements that means
12+ the number of columns are different for each row.
13+ So, for this scenario at the time of Ragged Array declaration at first,
14+ we have to define the number of total rows without defining the column
15+ number.
16+ Row number mentioning is mandatory.
17+ */
18+ for (int i =0 ;i <row ;i ++)
19+ {
20+ System .out .print ("Enter the number of Elements in row: " +(i +1 )+": " );
21+ arr [i ]=new int [sc .nextInt ()];
22+ }
23+ /*
24+ Here, we have defined the number of elements for each row.
25+ */
26+ //arr[0]= new int [4];
27+ //arr[1]=new int[5];
28+ //arr[2]=new int [2];
29+ for (int i =0 ;i <arr .length ;i ++)
30+ {
31+ for (int j =0 ;j <arr [i ].length ;j ++)
32+ {
33+ System .out .print ("Enter the elements in row:" +(i +1 )+": " );
34+ arr [i ][j ]=sc .nextInt ();
35+ }
36+ System .out .println ();
37+ }
38+ /*
39+ Here, we have initialized the Ragged Array after taking values from the user.
40+ */
41+ for (int i =0 ;i <arr .length ;i ++)
42+ {
43+ for (int j =0 ;j <arr [i ].length ;j ++)
44+ {
45+ System .out .print (arr [i ][j ]+" " );
46+ }
47+ System .out .println ();
48+ }
49+ //This block has been used to print all the elements of the Ragged Array.
50+ sc .close ();
51+ }
52+
53+ }