-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColsum2.java
More file actions
88 lines (68 loc) · 1.77 KB
/
Colsum2.java
File metadata and controls
88 lines (68 loc) · 1.77 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Scanner;
public class Colsum2 {
int mat[][], m, n;
public Colsum2(int mm, int nn) {
m = mm;
n = nn;
}
void readArray()
{
mat = new int[m][n];
Scanner x = new Scanner(System.in);
System.out.println("Enter array elements for MATRIX "+((int)(100*Math.random())));
for(int i=0; i<m; i++)
{
for(int j=0;j<n;j++)
{
mat[i][j] = x.nextInt();
}
}
x.close();
}
boolean check (Colsum2 A, Colsum2 B)
{
int sum1 = 0;
int sum2 = 0;
for(int i=0; i<n; i++)
{
sum1=0;
sum2=0;
for(int j=0; j<m; j++)
{
sum1 += A.mat[j][i];
sum2 += B.mat[j][i];
}
if (sum1==sum2) continue;
else return false;
}
return true;
}
void print()
{
// FIRST
System.out.println("---------- MATRIX "+(int)(100*Math.random())+"----------");
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(mat[i][j] + " ");
}
System.out.println();
}
}
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
System.out.println("Enter the rows and column for ");
int in=x.nextInt();
int im=x.nextInt();
Colsum2 C1 = new Colsum2(in, im);
Colsum2 C2 = new Colsum2(in, im);
C1.readArray();
C2.readArray();
System.out.println("========================Array print========================");
C1.print();
C2.print();
C1.check(C1,C2);
x.close();
}
}