forked from 14visheshjain/DataStructure-Algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjaggedarray.java
More file actions
38 lines (32 loc) · 868 Bytes
/
jaggedarray.java
File metadata and controls
38 lines (32 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package lecture5;
import java.util.Scanner;
public class jaggedarray {
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int[][] arr = takeinput();
display(arr);
}
public static int[][] takeinput() {
int rows;
System.out.println("rows?");
rows = scn.nextInt();
int[][] arr = new int[rows][];
for (int row = 0; row < arr.length; row++) {
System.out.println("col in row " + row);
int cols = scn.nextInt();
arr[row] = new int[cols];
for (int col = 0; col < cols; col++) {
System.out.println("arr[" + row + "-" + col + "]");
arr[row][col] = scn.nextInt();
}
}
return arr;
}
public static void display(int[][] arr) {
for (int row = 0; row < arr.length; row++) {
for (int j = 0; j < arr[row].length; j++)
System.out.print(arr[row][j] + " ");
System.out.println();
}
}
}