Java Matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LolaT
    New Member
    • Jul 2007
    • 22

    Java Matrix

    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.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    What was the actual error message?

    kind regards,

    Jos

    Comment

    • LolaT
      New Member
      • Jul 2007
      • 22

      #3
      Originally posted by JosAH
      What was the actual error message?

      kind regards,

      Jos

      The error message is:

      "Syntax error on token '&&', invalid OnlySynchronize d"


      thanks.

      Comment

      • madhoriya22
        Contributor
        • Jul 2007
        • 251

        #4
        Originally posted by LolaT
        The error message is:

        "Syntax error on token '&&', invalid OnlySynchronize d"


        thanks.
        Hi,
        Check your code ... Error is in this if condition
        Code:
        if (this.getnumOfRows()==B.getnumOfRows()){//[b]luk here[/b]
        				&&(this.getnumOfCols()==B.getnumOfCols()){

        Comment

        Working...