Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java. training
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Qazi Zain
Java. training
Commits
d043845c
Commit
d043845c
authored
Oct 17, 2024
by
Qazi Zain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new task are added
parent
e832acbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
MatrixMultiplication.java
src/JavaTrainingTask/Question9/MatrixMultiplication.java
+51
-0
main.java
src/JavaTrainingTask/Question9/main.java
+31
-0
No files found.
src/JavaTrainingTask/Question9/MatrixMultiplication.java
0 → 100644
View file @
d043845c
package
JavaTrainingTask
.
Question9
;
import
java.util.Scanner
;
public
class
MatrixMultiplication
{
MatrixMultiplication
()
{
System
.
out
.
println
(
"object is created"
);
}
public
static
void
inputMatrix
(
int
[][]
matrix
,
int
rows
,
int
cols
,
Scanner
input
,
String
matrixName
)
{
System
.
out
.
println
(
"Enter the elements of the "
+
matrixName
+
" matrix:"
);
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
for
(
int
j
=
0
;
j
<
cols
;
j
++)
{
matrix
[
i
][
j
]
=
input
.
nextInt
();
}
}
}
public
static
void
multiplyMatrices
(
int
[][]
matrixA
,
int
[][]
matrixB
,
int
[][]
matrixC
,
int
m
,
int
n
,
int
p
)
{
for
(
int
i
=
0
;
i
<
m
;
i
++)
{
for
(
int
j
=
0
;
j
<
p
;
j
++)
{
matrixC
[
i
][
j
]
=
0
;
for
(
int
k
=
0
;
k
<
n
;
k
++)
{
matrixC
[
i
][
j
]
+=
matrixA
[
i
][
k
]
*
matrixB
[
k
][
j
];
}
}
}
}
public
static
void
displayMatrix
(
int
[][]
matrix
,
int
rows
,
int
cols
)
{
System
.
out
.
println
(
"The product of the matrices is:"
);
for
(
int
i
=
0
;
i
<
rows
;
i
++)
{
for
(
int
j
=
0
;
j
<
cols
;
j
++)
{
System
.
out
.
print
(
matrix
[
i
][
j
]
+
" "
);
}
System
.
out
.
println
();
}
}
}
src/JavaTrainingTask/Question9/main.java
0 → 100644
View file @
d043845c
package
JavaTrainingTask
.
Question9
;
import
java.util.Scanner
;
public
class
main
{
public
static
void
main
(
String
[]
args
)
{
MatrixMultiplication
obj
=
new
MatrixMultiplication
();
Scanner
input
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter the number of rows of the first matrix:"
);
int
m
=
input
.
nextInt
();
System
.
out
.
println
(
"Enter the number of columns of the first matrix (and rows of the second):"
);
int
n
=
input
.
nextInt
();
System
.
out
.
println
(
"Enter the number of columns of the second matrix:"
);
int
p
=
input
.
nextInt
();
int
[][]
matrixA
=
new
int
[
m
][
n
];
int
[][]
matrixB
=
new
int
[
n
][
p
];
int
[][]
matrixC
=
new
int
[
m
][
p
];
obj
.
inputMatrix
(
matrixA
,
m
,
n
,
input
,
"first"
);
obj
.
inputMatrix
(
matrixB
,
n
,
p
,
input
,
"second"
);
obj
.
multiplyMatrices
(
matrixA
,
matrixB
,
matrixC
,
m
,
n
,
p
);
obj
.
displayMatrix
(
matrixC
,
m
,
p
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment