-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDarrays.java
More file actions
30 lines (27 loc) · 878 Bytes
/
Copy pathTwoDarrays.java
File metadata and controls
30 lines (27 loc) · 878 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
import java.util.Scanner;
public class TwoDarrays{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
/* MATRIX
1 2 3
4 5 6
7 8 9
*/
int[][] arr = new int[3][3]; // it is not necessary to write number of columns . Rows are necessary
//individual size of each array row can vary
//input
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < arr[row].length; col++) {
arr[row][col] = in.nextInt();
}
}
//output
for (int row = 0; row < arr.length; row++) {
for (int col = 0; col < arr[row].length; col++) { //we use arr[row].length because there can be any length of column. No fixed size
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
in.close();
}
}