-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayDemo.java
40 lines (35 loc) · 967 Bytes
/
ArrayDemo.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
import java.util.*;
class Array {
int arr[][];
Array(int row, int col) {
arr = new int[row][col];
}
public void rvalue() {
Random r = new Random();
for(int i = 0;i<arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
arr[i][j] = r.nextInt(25);
}
}
}
public void display() {
for(int i = 0;i<arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
}
public class ArrayDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of the 2D Array");
int row = sc.nextInt();
int col = sc.nextInt();
Array a = new Array(row, col);
a.rvalue();
a.display();
sc.close();
}
}