- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleArrayExample.java
More file actions
Latest commit
36 lines (27 loc) · 874 Bytes
/
Copy pathSimpleArrayExample.java
File metadata and controls
36 lines (27 loc) · 874 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
/* Computer Programming 1
*Simple 2-D Array example
*/
importjava.io.*;
importjava.util.*;
publicclassSimpleArrayExample
{
publicstaticvoidmain(String[] args) {
//two dimensional array without knowing its elements
int [][] array1 = newint [3][3];
//we fill the array with a nested loop and a scanner instance
Scannerreader = newScanner(System.in);
for(inti=0;i<array1.length;i++){
for(intj=0;j<array1.length;j++){
array1[i][j] = reader.nextInt();
}
}
// now we can print the array using another nested loop
for(inti=0;i<array1.length;i++){
for(intj=0;j<array1.length;j++){
System.out.print(array1[i][j]);
}
//we just print a new line
System.out.println();
}
}
}