java - Syntax problems in Matrix addition and multipication program -
i trying compile program entered 2 3*3 arrays , multipyling , adding both of them. giving me errors @ end due not running. cant remove these errors , need regarding how can remove them.
import java.util.scanner; public class matrix{ public static void main(string [] args){ int [][]= new int [3][3]; int b [][]= new int [3][3]; int c [][]= new int [3][3]; int d [][]= new int [3][3]; scanner in= new scanner(system.in); system.out.println("enter numbers in first matrix"); for( int r=0; r<3; r++){ for( int c=0; c<3; c++){ [r][c]= in.nextint(); } } system.out.println("matrix 1 : "); for(int = 0; < 3; i++) { for(int j = 0; j < 3; j++) { system.out.print(" "+ a[i][j]); } system.out.println(); } system.out.println("enter numbers in 2nd matrix"); for( int n=0; n<3; n++){ for( int m=0; m<3; m++){ b [n][m]= in.nextint(); } } system.out.println("matrix 2 : "); for(int k = 0; k < 3; k++) { for(int l = 0; l < 3; l++) { system.out.print(" "+b[k][l]); } system.out.println(); } //for multiplication of matrices for(int f = 0; f < 3; f++) { for(int s = 0; s < 3; s++) { for(int d = 0; d < 3; d++){ c[f][s] += a[f][d]*b[d][s]; } } } system.out.println("multiplication of both matrix : "); for(int x = 0; x < 3; x++) { for(int y = 0; y < 3; y++) { system.out.print(" "+c[x][y]); } system.out.println(); } } // addition of both matrices for(int w=0; w < 3; w++) { for(int u=0; u < 3; u++) { d[w][u] = a[w][u]+b[w][u]; } } system.out.println("addition of both matrix : "); for(int p = 0; p < 3; p++) { for(int q = 0; q < 3; q++) { system.out.print(" "+ d[p][q]); } system.out.println(); } } }
use ide , indent program. see issues. have 2 issues issues:
- you have parenthesis. not tell where.
- you have "d" defined twice variable.
again, it time download , use ide , indent code.
Comments
Post a Comment