forked from 14visheshjain/DataStructure-Algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharray2D.java
More file actions
36 lines (31 loc) · 873 Bytes
/
array2D.java
File metadata and controls
36 lines (31 loc) · 873 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
package lecture5;
import java.util.Scanner;
public class array2D {
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int[][] arr = takeinput();
display(arr);
}
public static int[][] takeinput() {
System.out.println("rows?");
int rows = s.nextInt();
System.out.println("cols?");
int cols = s.nextInt();
int[][] arr = new int[rows][cols];
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < arr[0].length; col++) {
System.out.println("arr[" + row + "-" + col + "]");
arr[row][col] = s.nextInt();
}
}
return arr;
}
public static void display(int[][] arr) {
for (int row = 0; row < arr.length; row++) {
for(int col = 0 ; col < arr[0].length ; col++) {
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
}
}