-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.java
More file actions
58 lines (51 loc) · 1.41 KB
/
Array.java
File metadata and controls
58 lines (51 loc) · 1.41 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package BASICS;
public class Array {
public static void main(String[] args) {
// int arr[]={5,3,9,10};
// int l=arr.length;
// //System.out.println(l);
// arr[3]=7;
// for(int i=0;i<l;i++){
// System.out.print(arr[i]+" ");
// }
// System.out.println();
// float deci[]={4.5f,3.99f,5.1f,6.7f};
// int l1=deci.length;
// for(int i=0;i<l1;i++){
// System.out.print(deci[i]+" ");
// }
//ABOVE ARRAYS ARE STATIC
//LETS CREATE A DYNAMIC ARRAY
//SYNTAX
// int arr[]= new int[5];
// arr[0]=2;
// arr[1]=5;
// arr[4]=9;
// for(int x:arr){
// System.out.println(x);
// }
int grid[][]=new int[5][6];
// grid[0][0]=1;
// grid[0][1]=2;
// grid[1][0]=3;
// grid[1][1]=4;
int n=grid.length;
int m=grid[0].length;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
//ASSIGN RANDOM VALUE:
grid[i][j]= (int)(Math.random()*10);
System.out.print(grid[i][j]+" ");
}
System.out.println();
}
System.out.println();
//ENHANCED FOR LOOP:
for(int r[]:grid){
for(int c:r){
System.out.print(c+" ");
}
System.out.println();
}
}
}