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 3981678
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:26:20+00:00 2026-05-20T05:26:20+00:00

Hey! I have matrix class and i want to add, multiply and take transpose

  • 0

Hey! I have matrix class and i want to add, multiply and take transpose of the matrix. for the structure of the code…I made a matrix class with a constructor, basic get methods and the methods to do the operations. Here’s what i have. i’m not sure if i need a constructor or not. I will have an application class that will call the main method. i want to know if so far I’m good with the thought process?

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

class Matrix {
    double[][] element;
    int row, col;

    Matrix(int a, int b) {
        row = a;
        col = b;
        element = new double[a][b];
    }

    public double getElement(int a, int b) {
        return element[a][b];
    }

    public int getRow() {
        return row;
    }

    public int getCol() {
        return col;
    }
}
  • 1 1 Answer
  • 2 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-20T05:26:21+00:00Added an answer on May 20, 2026 at 5:26 am

    Looks fairly ok so far (although the matrix is declared twice, as the commentor noted). It will definitely be useful to have a constructor in order to instantiate your internal matrix, otherwise you’ll (rather pointlessly) have to do it with another method, and you’d risk calling methods that try to access an uninstantiated matrix (which would not be useful).

    Regarding the two matrix declarations: it’s like any other variable. You declare with double[][] matrixname, then instantiate with matrixname = new double[a][b] (or do both at once if useful). If you do double matrixname = new double[a][b] inside the constructor, you’ll be creating a local variable there, which is then lost when the constructor code ends.

    Also, it might be good to use slightly better method names for clarity. getRow and getCol suggest, to me, that you’d be returning whole rows and whole columns, not the array bounds. Maybe think in terms of width and height?

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

Sidebar

Related Questions

Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey I have this kinda structure in my ini file I want to be
Hey I have a fairly basic question about regular expressions. I want to just
Hey guys have her an code where i add an option to a html
hey i have two tables i want to get the combined result out of
Hey i have been looking around and i cant find a way to get
Hey I have this code but it doesn't work because it is expecting a
Hey we have a library class (lib/Mixpanel) that calls delayed job as follows: class
Hey I have the following code which I'm using to isolate the a b
Hey I have following code like this public object RetrieveItemRun(int item) { if (dictionary.ContainsKey(item))

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.