FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/Other-Java-Programs/MatrixAddition.java at master · iamarav/Java-Programs · GitHub
iamarav
/
Java-Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
Other-Java-Programs
/
MatrixAddition.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (48 loc) · 1.61 KB
Breadcrumbs
Java-Programs
/
Other-Java-Programs
/
MatrixAddition.java
Copy path
File metadata and controls
60 lines (48 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
Scanner
;
public
class
MatrixAddition
{
public
static
void
main
(
String
[]
args
) {
int
lm1
=
1
,
hm1
=
1
,
lm2
=
1
,
hm2
=
1
;
//length of matrices 1/2; height of matrices 1/2
//minimum length is 1
Scanner
getArrayLength
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter length and height of Array 1: "
);
lm1
=
getArrayLength
.
nextInt
();
hm1
=
getArrayLength
.
nextInt
();
System
.
out
.
println
(
"Enter length and height of Array 1: "
);
lm2
=
getArrayLength
.
nextInt
();
hm2
=
getArrayLength
.
nextInt
();
double
array1
[][] =
new
double
[
lm1
][
hm1
];
double
array2
[][] =
new
double
[
lm2
][
hm2
];
//enter elements in array 1
System
.
out
.
println
(
"Enter the elements of first array: "
);
Scanner
sm
=
new
Scanner
(
System
.
in
);
for
(
int
x
=
0
;
x
<
lm1
;
x
++) {
for
(
int
y
=
0
;
y
<
hm1
;
y
++) {
array1
[
x
][
y
]=
sm
.
nextDouble
();
}
}
//enter elements in array 2
System
.
out
.
println
(
"---
\n
Enter the elements of second array: "
);
for
(
int
x
=
0
;
x
<
lm2
;
x
++) {
for
(
int
y
=
0
;
y
<
hm2
;
y
++) {
array2
[
x
][
y
]=
sm
.
nextDouble
();
}
}
getArrayLength
.
close
();
sm
.
close
();
// closing the scanner
addition
(
array1
,
array2
,
lm1
,
lm2
,
hm1
,
hm2
);
System
.
out
.
println
(
"---
\n
The Program has ended."
);
}
static
void
addition
(
double
[][]
array1
,
double
[][]
array2
,
int
lm1
,
int
lm2
,
int
hm1
,
int
hm2
) {
int
temp
=
0
;
String
result
=
""
;
for
(
int
i
=
0
;
i
<
lm1
;
i
++) {
for
(
int
j
=
0
;
j
<
hm2
;
j
++) {
temp
= (
int
) (
array1
[
i
][
j
]+
array2
[
i
][
j
]);
result
=
result
+
temp
+
" "
;
}
result
=
result
+
"
\n
"
;
}
System
.
out
.
println
(
"The final result of addition is:
\n
"
+
result
);
//return result;
}
}
Back
|
FazBrowse Home
|
New Git URL