Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Friday at 7:43 PM
NURSING , CAREGIVER , HOTEL & BEAUTY COURSES
IVA Para Medical Campus
Updated:
Thursday at 9:24 AM
Handmade Character Soft Toys Peppa Pig Family
anil1961
Updated:
Wednesday at 9:58 PM
Ad icon
Video Content Creator
pramukag
Updated:
Jun 28, 2026
Ad icon
QA Engineer Intern
pramukag
Updated:
Jun 28, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Thread for Programming and Realeted Topics
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="rclakmal" data-source="post: 5924914" data-attributes="member: 98858"><p><strong>here is my code !!!</strong></p><p></p><p>[code]</p><p>/*</p><p> * To change this template, choose Tools | Templates</p><p> * and open the template in the editor.</p><p> */</p><p>package example1;</p><p></p><p>import java.util.Scanner;</p><p></p><p>class MatrixMultiplier {</p><p></p><p> int p, q, s, r;</p><p> static Scanner input = new Scanner(System.in);</p><p></p><p> void getInput() {</p><p></p><p> System.out.println("Enter Dimenison of the first Matrix(Etc : 2 2)");</p><p> p = input.nextInt();</p><p> q = input.nextInt();</p><p> System.out.println("Enter Dimenison of the Second Matrix(Etc : 2 2)");</p><p> r = input.nextInt();</p><p> s = input.nextInt();</p><p> if (p != q) {</p><p> System.out.println("Matrixs Dimensions mismatch");</p><p> getInput();</p><p></p><p></p><p></p><p> }</p><p> }</p><p></p><p> int[][] getMatrixA(int p, int q) {</p><p></p><p> int[][] A = new int[p][q];</p><p> System.out.println("Enter Matrix A");</p><p> for (int i = 0; i < p; i++) {</p><p> for (int j = 0; j < q; j++) {</p><p> A[i][j] = input.nextInt();</p><p> }</p><p> }</p><p> return A;</p><p></p><p> }</p><p></p><p> int[][] getMatrixB(int r, int s) {</p><p></p><p> int[][] B = new int[r][s];</p><p> System.out.println("Enter Matrix B");</p><p> for (int i = 0; i < r; i++) {</p><p> for (int j = 0; j < s; j++) {</p><p> B[i][j] = input.nextInt();</p><p> }</p><p> }</p><p> return B;</p><p></p><p> }</p><p></p><p> int[][] multiply(int[][] A, int[][] B, int p, int q, int s) {</p><p> int[][] C = new int[p][s];</p><p> for (int i = 0; i < p; i++) {</p><p> for (int j = 0; j < s; j++) {</p><p> C[i][j] = 0;</p><p> for (int k = 0; k < q; k++) {</p><p> C[i][j] += A[i][k] * B[k][j];</p><p> }</p><p> }</p><p> }</p><p> return C;</p><p> }</p><p></p><p> void printResult(int[][] C) {</p><p> System.out.println("Answer :");</p><p> for (int i = 0; i < C.length; i++) {</p><p> for (int j = 0; j < C[i].length; j++) {</p><p> System.out.print(" " + C[i][j]);</p><p> }</p><p> System.out.println("");</p><p> }</p><p></p><p> }</p><p></p><p> public static void main(String[] args) {</p><p> MatrixMultiplier mm1 = new MatrixMultiplier();</p><p> mm1.getInput();</p><p> mm1.printResult(mm1.multiply(mm1.getMatrixA(mm1.p,mm1.q),mm1.getMatrixB(mm1.r, mm1.s),</p><p> mm1.p,mm1.q,mm1.s));</p><p></p><p> }</p><p>}</p><p>[/code]</p><p></p><p>Try if u have installed java in ur PC !!!! Its working for any dimension!!!!!!</p></blockquote><p></p>
[QUOTE="rclakmal, post: 5924914, member: 98858"] [b]here is my code !!![/b] [code] /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package example1; import java.util.Scanner; class MatrixMultiplier { int p, q, s, r; static Scanner input = new Scanner(System.in); void getInput() { System.out.println("Enter Dimenison of the first Matrix(Etc : 2 2)"); p = input.nextInt(); q = input.nextInt(); System.out.println("Enter Dimenison of the Second Matrix(Etc : 2 2)"); r = input.nextInt(); s = input.nextInt(); if (p != q) { System.out.println("Matrixs Dimensions mismatch"); getInput(); } } int[][] getMatrixA(int p, int q) { int[][] A = new int[p][q]; System.out.println("Enter Matrix A"); for (int i = 0; i < p; i++) { for (int j = 0; j < q; j++) { A[i][j] = input.nextInt(); } } return A; } int[][] getMatrixB(int r, int s) { int[][] B = new int[r][s]; System.out.println("Enter Matrix B"); for (int i = 0; i < r; i++) { for (int j = 0; j < s; j++) { B[i][j] = input.nextInt(); } } return B; } int[][] multiply(int[][] A, int[][] B, int p, int q, int s) { int[][] C = new int[p][s]; for (int i = 0; i < p; i++) { for (int j = 0; j < s; j++) { C[i][j] = 0; for (int k = 0; k < q; k++) { C[i][j] += A[i][k] * B[k][j]; } } } return C; } void printResult(int[][] C) { System.out.println("Answer :"); for (int i = 0; i < C.length; i++) { for (int j = 0; j < C[i].length; j++) { System.out.print(" " + C[i][j]); } System.out.println(""); } } public static void main(String[] args) { MatrixMultiplier mm1 = new MatrixMultiplier(); mm1.getInput(); mm1.printResult(mm1.multiply(mm1.getMatrixA(mm1.p,mm1.q),mm1.getMatrixB(mm1.r, mm1.s), mm1.p,mm1.q,mm1.s)); } } [/code] Try if u have installed java in ur PC !!!! Its working for any dimension!!!!!! [/QUOTE]
Insert quotes…
Verification
Nawa warak dahaya keeyada? (Namaya wadi kireema dahaya)
Post reply
Top
Bottom