forked from avinashbest/java-coding-ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions2dArray.java
More file actions
38 lines (33 loc) · 1.09 KB
/
Copy pathFunctions2dArray.java
File metadata and controls
38 lines (33 loc) · 1.09 KB
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 twoDimensionalArray;
import java.util.Scanner;
public class Functions2dArray {
public static void print2dArray(int[][] arr) {
int row = arr.length;
int column = arr[0].length;
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
public static int[][] takeInput() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter number of rows:");
int row = scan.nextInt();
System.out.println("Enter number of columns:");
int column = scan.nextInt();
int[][] arr = new int[row][column];
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
System.out.println("Enter the element at " + i + "th rows " + j + "th column:");
arr[i][j] = scan.nextInt();
}
}
return arr;
}
public static void main(String[] args) {
int[][] arr = takeInput();
print2dArray(arr);
}
}