-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.java
54 lines (46 loc) · 1.52 KB
/
arrays.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.lang.reflect.Array;
import java.util.Scanner;
public class arrays {
public static void main(String[] args) {
// 1d array
String[] array = {"a", "b" , "c"};
// type [] name = {array}
/* there are two ways to declare arrays :- 1st is decclare directly with values and second (below given ) i.e. decalre size first and then declare values by indexing. */
int [] array2 = new int[3];
array2[0] = 1;
array2[1] = 2;
array2[2] = 3;
// array.length gives the size of an array.
// 2d array
/* 2d array is collection of row and columns
*
* (row,column)
*
* it is zero index based as java is zero index based language. Hence 1st block is 0,0.
*
* size of array is row*column * size of datatype
*
* declaration:-
* type[][] name = new type[rows][columns]
*
* indexing also in same way [row][column]
*
*
*/
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int column = sc.nextInt();
int [][] numbers = new int[row][column];
for(int i = 0; i < row; i++){
for (int j = 0; j<column; j++){
numbers[i][j] = sc.nextInt();
}
}
for(int i = 0; i <row; i++){
for (int j = 0; j<column; j++){
System.out.print(numbers[i][j] + " ");
}
System.out.println();
}
}
}