-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleTesting.java
68 lines (59 loc) · 1.73 KB
/
ConsoleTesting.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Computer Programming 1
*/
//Preincrement vs Postincrement
import java.io.*;
import java.util.*;
public class ConsoleTesting
{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Please Enter array size");
int size = reader.nextInt();
int [][] arr1 = new int [size][size];
int [][] arr2 = new int [size][size];
int [][] arr3 = new int [size][size];
int cellValue=0,j,i,k;
Random rand = new Random();
//filling the arrays with some values
for(i =0; i<size; i++){
for(j = 0; j<size;j++){
arr1 [i][j] = 1+rand.nextInt(9);
arr2 [i][j] = 1+rand.nextInt(9);
}
}
// System.out.println(1+rand.nextInt(9));
for(i = 0; i<size; i++){
for(j =0;j<size;j++){
for(k=0;k<size;k++){
cellValue += arr1[i][k] * arr2[k][j];
}
arr3[i][j] = cellValue;
cellValue =0;
}
}
//printing arr1
System.out.print("\n array1\n");
for(i =0; i<size; i++){
for(j = 0; j<size;j++){
System.out.print(arr1 [i][j]+"\t");
}
System.out.println();
}
//printing arr2
System.out.print("\n array2\n");
for(i =0; i<size; i++){
for(j = 0; j<size;j++){
System.out.print(arr2 [i][j]+"\t");
}
System.out.println();
}
//printing arr3
System.out.print("\n array3\n");
for(i =0; i<size; i++){
for(j = 0; j<size;j++){
System.out.print(arr3 [i][j]+"\t");
}
System.out.println();
}
}
}