Skip to main content
Cleaned up and removed homework tag.
Source Link
Piotr Gwiazda
  • 12.2k
  • 13
  • 62
  • 94

Im working on this code and expecting How to display object as a matrix but thats what came up...Matrix@2c78bc3b Matrix@2a8ddc4cString properly

Im working on this code and expecting a matrix to be printed but thats what came up Matrix@2c78bc3b Matrix@2a8ddc4c

This is a code example:

public class Matrix { public static int rows; public static int colms;//columns public static int[][] numbers; public Matrix(int[][] numbers) { numbers = new int[rows][colms]; } public static boolean isSquareMatrix(Matrix m) { //rows = numbers.length; //colms = numbers[0].length; if(rows == colms) return true; else return false; } public static Matrix getTranspose(Matrix trans) { trans = new Matrix(numbers); for(int i =0; i < rows; i++) { for(int j = 0; j < colms; j++) { trans.numbers[i][j] = numbers[j][i]; } } return trans; } public static void main(String[] args) { int[][] m1 = new int[][]{{1,4}, {5,3}}; Matrix Mat = new Matrix(m1); System.out.print(Mat); System.out.print(getTranspose(Mat)); } } 

Im working on this code and expecting a matrix but thats what came up...Matrix@2c78bc3b Matrix@2a8ddc4c

public class Matrix { public static int rows; public static int colms;//columns public static int[][] numbers; public Matrix(int[][] numbers) { numbers = new int[rows][colms]; } public static boolean isSquareMatrix(Matrix m) { //rows = numbers.length; //colms = numbers[0].length; if(rows == colms) return true; else return false; } public static Matrix getTranspose(Matrix trans) { trans = new Matrix(numbers); for(int i =0; i < rows; i++) { for(int j = 0; j < colms; j++) { trans.numbers[i][j] = numbers[j][i]; } } return trans; } public static void main(String[] args) { int[][] m1 = new int[][]{{1,4}, {5,3}}; Matrix Mat = new Matrix(m1); System.out.print(Mat); System.out.print(getTranspose(Mat)); } } 

How to display object as a String properly

Im working on this code and expecting a matrix to be printed but thats what came up Matrix@2c78bc3b Matrix@2a8ddc4c

This is a code example:

public class Matrix { public static int rows; public static int colms;//columns public static int[][] numbers; public Matrix(int[][] numbers) { numbers = new int[rows][colms]; } public static boolean isSquareMatrix(Matrix m) { //rows = numbers.length; //colms = numbers[0].length; if(rows == colms) return true; else return false; } public static Matrix getTranspose(Matrix trans) { trans = new Matrix(numbers); for(int i =0; i < rows; i++) { for(int j = 0; j < colms; j++) { trans.numbers[i][j] = numbers[j][i]; } } return trans; } public static void main(String[] args) { int[][] m1 = new int[][]{{1,4}, {5,3}}; Matrix Mat = new Matrix(m1); System.out.print(Mat); System.out.print(getTranspose(Mat)); } } 
edited tags
Link
oksayt
  • 4.4k
  • 1
  • 25
  • 42
added 208 characters in body
Source Link
thyrgle
thyrgle

public class Matrix {

public class Matrix { public static int rows;  public static int colms;//columns  public static int[][] numbers;    public Matrix(int[][] numbers)  {     numbers = new int[rows][colms];    }    public static boolean isSquareMatrix(Matrix m)  {   //rows = numbers.length;   //colms = numbers[0].length;     if(rows == colms)   return true;   else   return false;  }    public static Matrix getTranspose(Matrix trans)  {   trans = new Matrix(numbers);     for(int i =0; i < rows; i++)   {   for(int j = 0; j < colms; j++)   {   trans.numbers[i][j] = numbers[j][i];   }   }   return trans;  }        public static void main(String[] args)  {   int[][] m1 = new int[][]{{1,4}, {5,3}};   Matrix Mat = new Matrix(m1);     System.out.print(Mat);   System.out.print(getTranspose(Mat));    } } 

}

public class Matrix {

public static int rows; public static int colms;//columns public static int[][] numbers; public Matrix(int[][] numbers) { numbers = new int[rows][colms]; } public static boolean isSquareMatrix(Matrix m) { //rows = numbers.length; //colms = numbers[0].length; if(rows == colms) return true; else return false; } public static Matrix getTranspose(Matrix trans) { trans = new Matrix(numbers); for(int i =0; i < rows; i++) { for(int j = 0; j < colms; j++) { trans.numbers[i][j] = numbers[j][i]; } } return trans; } public static void main(String[] args) { int[][] m1 = new int[][]{{1,4}, {5,3}}; Matrix Mat = new Matrix(m1); System.out.print(Mat); System.out.print(getTranspose(Mat)); } 

}

public class Matrix { public static int rows;  public static int colms;//columns  public static int[][] numbers;    public Matrix(int[][] numbers)  {     numbers = new int[rows][colms];    }    public static boolean isSquareMatrix(Matrix m)  {   //rows = numbers.length;   //colms = numbers[0].length;     if(rows == colms)   return true;   else   return false;  }    public static Matrix getTranspose(Matrix trans)  {   trans = new Matrix(numbers);     for(int i =0; i < rows; i++)   {   for(int j = 0; j < colms; j++)   {   trans.numbers[i][j] = numbers[j][i];   }   }   return trans;  }        public static void main(String[] args)  {   int[][] m1 = new int[][]{{1,4}, {5,3}};   Matrix Mat = new Matrix(m1);     System.out.print(Mat);   System.out.print(getTranspose(Mat));    } } 
Source Link
W M
  • 127
  • 2
  • 2
  • 5
Loading