Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde7585e

Browse files
authored
Merge pull request#161 from Poulami769988/main
Ragged Array using Java.
2 parents0e153e6 +87e2a9a commitde7585e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

‎Ragged_Array.java‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
importjava.util.*;
2+
publicclassRagged_Array {
3+
4+
publicstaticvoidmain(String[]args) {
5+
Scannersc =newScanner(System.in);
6+
System.out.print("Enter the Number of Rows in the Ragged array: ");
7+
introw =sc.nextInt();
8+
//Asking for the number of rows
9+
int [][]arr=newint [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(inti=0;i<row;i++)
19+
{
20+
System.out.print("Enter the number of Elements in row: "+(i+1)+": ");
21+
arr[i]=newint[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 (inti=0;i<arr.length;i++)
30+
{
31+
for(intj=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 (inti=0;i<arr.length;i++)
42+
{
43+
for(intj=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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp