I am making a program that deals with matrices in Java.
I keep getting an error and I don't know how to fix it
my code so far is
[code=java]
import java.io.*;
import java.util.*;
import java.util.Scann er;
public class Matrix {
public float elements[][];
public int numOfCols;
public int numOfRows;
public int getnumOfRows(){
return numOfRows;
}
public int getnumOfCols(){
return numOfCols;
}
public float get(int row, int col){
return elements[row][col];
}
public void set(float value, int row, int col){
elements[row][col]=value;
}
public void load (Scanner read){
numOfRows=read. nextInt();
numOfCols=read. nextInt();
float[][]elements=new float[numOfRows][numOfCols];
for (int i=0; i<numOfRows; i++){
for (int j=0; j<numOfCols; j++)
elements[i][j]=read.nextFloat ();}
}
public Matrix add;Matrix A (Matrix B){
if (this.getnumOfR ows()==B.getnum OfRows()){
&&(this.getnumO fCols()==B.getn umOfCols()){
Matrix C=new Matrix();
C.numOfRows=thi s.getnumOfRows( );
C.numOfCols=thi s.getnumOfCols( );
C.elements=new float[getnumOfRows()][getnumOfCols()];
for (int row=0; row<numOfRows; row++){
for (int col=0; col<numOfCols; col++){
float value=this.get( row,col)+B.get( row,col);
C.set(value,row ,col);}}
return C;}
else{
return null;[/code]
the error occurs at
&&(this.getnumO fCols()==B.getn umOfCols()){
that line. If anyone has any suggestions on how to fix it, or what it is exactly that i'm doing wrong, help would be appreciated. Thanks.
I keep getting an error and I don't know how to fix it
my code so far is
[code=java]
import java.io.*;
import java.util.*;
import java.util.Scann er;
public class Matrix {
public float elements[][];
public int numOfCols;
public int numOfRows;
public int getnumOfRows(){
return numOfRows;
}
public int getnumOfCols(){
return numOfCols;
}
public float get(int row, int col){
return elements[row][col];
}
public void set(float value, int row, int col){
elements[row][col]=value;
}
public void load (Scanner read){
numOfRows=read. nextInt();
numOfCols=read. nextInt();
float[][]elements=new float[numOfRows][numOfCols];
for (int i=0; i<numOfRows; i++){
for (int j=0; j<numOfCols; j++)
elements[i][j]=read.nextFloat ();}
}
public Matrix add;Matrix A (Matrix B){
if (this.getnumOfR ows()==B.getnum OfRows()){
&&(this.getnumO fCols()==B.getn umOfCols()){
Matrix C=new Matrix();
C.numOfRows=thi s.getnumOfRows( );
C.numOfCols=thi s.getnumOfCols( );
C.elements=new float[getnumOfRows()][getnumOfCols()];
for (int row=0; row<numOfRows; row++){
for (int col=0; col<numOfCols; col++){
float value=this.get( row,col)+B.get( row,col);
C.set(value,row ,col);}}
return C;}
else{
return null;[/code]
the error occurs at
&&(this.getnumO fCols()==B.getn umOfCols()){
that line. If anyone has any suggestions on how to fix it, or what it is exactly that i'm doing wrong, help would be appreciated. Thanks.
Comment