Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3991078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:34:19+00:00 2026-05-20T06:34:19+00:00

i have a class Matrix and I use the this pointer in the application

  • 0

i have a class Matrix and I use the this pointer in the application class to access the methods of the Matrix class. For some reason it doesn’t identify the methods. This is a code snippet and it gives me an error starting with the AddMatrix method when I use

import java.io.*;
import java.util.*;
import java.util.Scanner;

class Matrix {
double [][] element;
int rows, cols ;

Matrix(int rows, int cols){
this.rows = rows;
this.cols = cols;
element = new double [rows][cols];
}

public double getValue (int row, int col){
return element[row][col];
}

public void setValue (int row, int col, double value){
element[row][col] = value;  
}

public int getNoRows(){  // returns the total number of rows
return rows;
}

public int getNoCols(){ // returns the total number of cols
return cols;
}

 // The methods for the main calculations

public Matrix AddMatrix(Matrix m2){
int row1 = getNoRows();
int col1 = getNoCols();
Matrix result = new Matrix(row1, col1);

 for (int i=0; i<row1; i++){
   for (int j=0; j<col1; j++) {
      result.setValue(i,j, (getValue(i,j) + m2.getValue(i,j)));
    }
 }
return result;
}

 public Matrix  MultiplyMatrix(Matrix m2){
   if (this.getNoCols != m2.getNoRows)
   throw new IllegalArgumentException ("matrices can't be multiplied");
   int row2 = this.getNoRows();
   int col2 = m2.getNoCols();
   Matrix result = new Matrix(row2, col2);
   for (int i=0; i<row2; i++){
   for (int j=0; j<col2; j++){
         result.setValue(i,j,(this.getValue(i,j)*m2.getValue(i,j)));
      }
  }
 return result;

 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:34:19+00:00Added an answer on May 20, 2026 at 6:34 am

    this.getNoCols != m2.getNoRows
    should be
    this.getNoCols() != m2.getNoRows()

    You are using the syntax to access a variable instead of the syntax for calling a method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code base, in which for Matrix class, these two definitions are
I have an abstract class A that define abstract methods. This means that, for
In one of the application I am working I have found this code -
Wen I have this code: import java.util.Scanner; import java.util.Arrays; public class Ex02 { /**
I have the following class: template <typename T> class matrix { private: int _n;
Suppose I have a rather large class Matrix , and I've overloaded operator== to
I have a class Matrix which contains ArrayList<ArrayList<Double>> matrix; inside, and I want to
I have a mathematical matrix class. It contains a member function which is used
In my Android application I have created an SVG image converter class. It parses
I have a class to parse a matrix that keeps the result in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.